#include<stdio.h>
#define TOTAL_ELEMENTS (sizeof(array) / sizeof(array[0]))
int array[] = {23,34,12,17,204,99,16};
int main()
{
int d;
for(d=-1;d <= (TOTAL_ELEMENTS-2);d++)
printf("%d\n",array[d+1]);
return 0;
}
The above snippet doesnt print the array as expected.
I think the error is in the Test-condition in for loop.
If i cast it to INT [(int)TOTAL_ELEMENTS-2)] than its working fine.
y is it so..can sbd tell me what the return type of sizeof
is?? 5 1123
In article <11**********************@g44g2000cwa.googlegroups .com>,
sasiraj <va*********@gmail.com> wrote: #define TOTAL_ELEMENTS (sizeof(array) / sizeof(array[0]))
int d;
for(d=-1;d <= (TOTAL_ELEMENTS-2);d++)
I think the error is in the Test-condition in for loop. If i cast it to INT [(int)TOTAL_ELEMENTS-2)] than its working fine. y is it so..can sbd tell me what the return type of sizeof is??
sizeof has type size_t . The exact width of size_t is unspecified,
but one thing that -is- specified about it is that it is unsigned.
You might be having difficulty with comparing a negative int
to an unsigned integral type.
--
"This was a Golden Age, a time of high adventure, rich living and
hard dying... but nobody thought so." -- Alfred Bester, TSMD
In article <11**********************@g44g2000cwa.googlegroups .com>,
sasiraj <va*********@gmail.com> wrote: #include<stdio.h>
#define TOTAL_ELEMENTS (sizeof(array) / sizeof(array[0])) int array[] = {23,34,12,17,204,99,16};
int main() { int d;
for(d=-1;d <= (TOTAL_ELEMENTS-2);d++) printf("%d\n",array[d+1]);
return 0; }
The above snippet doesnt print the array as expected. I think the error is in the Test-condition in for loop. If i cast it to INT [(int)TOTAL_ELEMENTS-2)] than its working fine. y is it so..can sbd tell me what the return type of sizeof is??
From K&R2, Section A6.5:
[automatic conversion of operands]
If either operand is unsigned int, the other is
converted to unsigned int.
Thus the -1 in d=-1 is converted (unsigned int)(-1) which
generally is a pretty large number.
--
Rouben Rostamian
sasiraj wrote: #include<stdio.h>
#define TOTAL_ELEMENTS (sizeof(array) / sizeof(array[0])) int array[] = {23,34,12,17,204,99,16};
int main() { int d;
for(d=-1;d <= (TOTAL_ELEMENTS-2);d++) printf("%d\n",array[d+1]);
return 0; }
The above snippet doesnt print the array as expected.
hello sasi
Do you want to print the array in order as it is declared?If yes they
are printing in order .
and if no then clarify in which order? I think the error is in the Test-condition in for loop. If i cast it to INT [(int)TOTAL_ELEMENTS-2)] than its working fine. y is it so..can sbd tell me what the return type of sizeof is??
sasiraj wrote: #include<stdio.h>
#define TOTAL_ELEMENTS (sizeof(array) / sizeof(array[0]))
Just make it:
#define TOTAL_ELEMENTS (signed)(sizeof(array) / sizeof(array[0]))
Try going through sizeof help and you would have the answer yourself.
int array[] = {23,34,12,17,204,99,16};
int main() { int d;
for(d=-1;d <= (TOTAL_ELEMENTS-2);d++)
OR another choice could be to initialise d to 0. But I guess you did
not want this. Soo, go through sizeof help.
printf("%d\n",array[d+1]);
return 0; }
The above snippet doesnt print the array as expected. I think the error is in the Test-condition in for loop. If i cast it to INT [(int)TOTAL_ELEMENTS-2)] than its working fine. y is it so..can sbd tell me what the return type of sizeof is??
ice wrote: sasiraj wrote:
[snip program] The above snippet doesnt print the array as expected. hello sasi Do you want to print the array in order as it is declared?If yes they are printing in order . and if no then clarify in which order? I think the error is in the Test-condition in for loop. If i cast it to INT [(int)TOTAL_ELEMENTS-2)] than its working fine. y is it so..can sbd tell me what the return type of sizeof is??
I dont think its should print the contents without you modifying the
#define preprocessor. Please check once again.
OR probably I need to check my compiler. ;) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Sims |
last post by:
Hi
I have a table with something like
ID PARENT
0 | -1
1 | -1
2 | 1
3 | 1
|
by: XXXXXX.working.in.my.blood |
last post by:
hi all,
i need help with linked lists...
the problem is this, "reverse the contents of a singly linked list
without using a temporary node"...
solution with code will be appreciated...
|
by: Rex |
last post by:
Hi All - I have a question that I think MIGHT be of interest to a
number of us developers. I am somewhat new to VIsual Studio 2005 but
not new to VB. I am looking for ideas about quick and...
|
by: naknak4 |
last post by:
Introduction
This assignment requires you to develop solutions to the given problem
using several different approaches (which actually involves using three
different STL containers). You will...
|
by: naknak |
last post by:
Introduction
This assignment requires you to develop solutions to the given problem
using several different approaches (which actually involves using three
different STL containers). You will...
|
by: kickioly |
last post by:
Hi everyone, this is my first time here and i hope it will not be the
last, i have a problem here solving this C++ problem,and i hope that
someone here to solve it and i'll be happy if you do it...
|
by: Mr. SweatyFinger |
last post by:
where have they all gone.
alt.suicide?
alt.findContol.then.slit.your.own.throat?
|
by: jvdb |
last post by:
Hi there,
I am quite new on python programming and need some help on solving my
problem..
I have to make a (python) program which deletes files from
directories. I don't think deleting, etc....
|
by: NatRoger |
last post by:
Hi,
We are using DB2 V7 (MVS) in our shop, which dont have the luxury of
the 'WITH clause' - CTE support to accomplish recursive queries.
Here is my problem -
Table1
From-ID To-ID
A1 ...
|
by: Chuck Cheeze |
last post by:
This might be in the wrong group, but...
Here is an example of my data:
entry_id cat_id
1 20
2 25
3 30
4 25
5 35
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |