Output of C Program | Set 28 Last Updated : 27 Dec, 2016 Summarize Comments Improve Suggest changes Share Like Article Like Report Predict the output of following C program. Question 1 C #include <stdio.h> int main() { char a = 30; char b = 40; char c = 10; char d = (a * b) / c; printf ("%d ", d); return 0; } At first look, the expression (a*b)/c seems to cause arithmetic overflow because signed characters can have values only from -128 to 127 (in most of the C compilers), and the value of subexpression '(a*b)' is 1200. For example, the following code snippet prints -80 on a 32 bit little endian machine. char d = 1200; printf ("%d ", d); Arithmetic overflow doesn't happen in the original program and the output of the program is 120. In C, char and short are converted to int for arithmetic calculations. So in the expression '(a*b)/c', a, b and c are promoted to int and no overflow happens. Question 2 C #include<stdio.h> int main() { int a, b = 10; a = -b--; printf("a = %d, b = %d", a, b); return 0; } Output: a = -10, b = 9 The statement 'a = -b--;' compiles fine. Unary minus and unary decrement have save precedence and right to left associativity. Therefore '-b--' is treated as -(b--) which is valid. So -10 will be assigned to 'a', and 'b' will become 9. Try the following program as an exercise. C #include<stdio.h> int main() { int a, b = 10; a = b---; printf("a = %d, b = %d", a, b); return 0; } Comment More infoAdvertise with us Next Article Output of C Program | Set 21 K kartik Follow Improve Article Tags : C Language C-Output Similar Reads Output of C programs | Set 8 Predict the output of below C programs. Question 1: c #include<stdio.h> int main() { int x = 5, p = 10; printf("%*d", x, p); getchar(); return 0; } Output: 10 Explanation: Please see standard printf function definition int printf ( const char * format, ... ); format: String that cont 3 min read Output of C Program | Set 27 Predict the output of following C programs. Question 1 C #include <stdio.h> int main(void) { int i; int power_of_ten[5] = { 00001, 00010, 00100, 01000, 10000, }; for (i = 0; i < 5; ++i) printf("%d ", power_of_ten[i]); printf("\n"); return 0; } In the above example, we ha 3 min read Output of C Program | Set 21 Predict the output of following C programs. Question 1 C #include<stdio.h> #define fun (x) (x)*10 int main() { int t = fun(5); int i; for(i = 0; i < t; i++) printf("GeeksforGeeks\n"); return 0; } Output: Compiler Error There is an extra space in macro declaration which causes fun 2 min read Output of C Program | Set 18 Predict the output of following C programs.Question 1 C #include<stdio.h> int fun() { static int num = 40; return num--; } int main() { for(fun(); fun(); fun()) { printf("%d ", fun()); } getchar(); return 0; } Output: 38 35 32 29 26 23 20 17 14 11 8 5 2Since num is static in fun(), t 2 min read Output of C Program | Set 24 Predict the output of following C programs:Difficulty Level: Rookie Question 1 C #include<stdio.h> int main() { int arr[] = {10, 20, 30, 40, 50, 60}; int *ptr1 = arr; int *ptr2 = arr + 5; printf ("ptr2 - ptr1 = %d\n", ptr2 - ptr1); printf ("(char*)ptr2 - (char*) ptr1 = %d", 3 min read Output of C Program | Set 20 Predict the outputs of following C programs. Question 1 C int main() { int x = 10; static int y = x; if(x == y) printf("Equal"); else if(x > y) printf("Greater"); else printf("Less"); getchar(); return 0; } Output: Compiler Error In C, static variables can only be in 2 min read Like