Predict the output of below program.
Output: Nothing is printed as loop condition is not true for the first time itself.
The result of sizeof for an array operand is number of elements in the array multiplied by size of an element in bytes. So value of the expression TOTAL_ELEMENTS in the above program is 7.
The data type of the sizeof result is unsigned int or unsigned long depending upon the compiler implementation. Therefore, in the loop condition i <= (TOTAL_ELEMENTS-2), an int is compared to an unsigned value. int is implicitly converted to unsigned (true for both unsigned int and unsigned long). So -1 ( unsigned equivalent 4294967295 if integers are stored using 32 bit) is compared to TOTAL_ELEMENTS - 2 and the condition is not true for the first time itself.
Please write comments if you find anything incorrect in the above post.
- Menu Driven Program to convert MKS to CGS and CGS to MKS
- Output of Python Programs | (Dictionary)
- Output of C++ programs | Set 50
- delete() in C++
- Output of C++ Programs | Set 49
- Output of C programs | Set 65 (If-Else)
- Python List
- Output of Python Programs | Set 24 (Sets)
- Output of Java Programs | Set 53 (String Comparison)
- Output of Java Programs | Set 52 (Strings Class)
- Output of Python Programs | Set 23 (String in loops)
- Output of Python Programs | Set 22 (Loops)
- Output of Python Programs | Set 21 (Bool)
- Output of Python Programs | Set 20 (Tuples)