Output of C programs | Set 53 (Operators) Last Updated : 06 Sep, 2017 Summarize Comments Improve Suggest changes Share Like Article Like Report Prerequisite: Operators in C 1. What will be the output of the following? CPP #include <stdio.h> int main(void) { int a; int b = 1; int x[5] = { 1, 2, 3, 4, 5 }; a = 5 * 4 + x[--b] - (9 / b); printf("%d", a); return 0; } Options: 1. 12 2. Abnormal Termination 3. 21 4. No Output The answer is option(2). Explanation : Here the square bracket has the highest priority that's why it is evaluated first. After that parenthesis enjoys the priority but we have error because float point exception occurs when we divide 9/0. 2. What will be the output of the following? CPP #include <stdio.h> int main(void) { int a; int b = 1; int x[5] = { 1, 2, 3, 4, 5 }; a = 5 * 4 + x[b++] - (9 / b); printf("%d", a); return 0; } Options: 1. 12 2. 20 3. 18 4. No Output The answer is option(3). Explanation:Here the square bracket has the highest priority that's why it is evaluated first. After that parenthesis enjoys the priority.Now a=5*4+x[b++]-(9/b)=18. Refer: www.geeksforgeeks.org/c-operator-precedence-associativity/ 3. what will be the output of the following? CPP #include <stdio.h> int main(void) { int a; int i = 1; int b = 10 * i + sizeof(--i) + 4 - 10 / i; printf("%d", b); return 0; } Options: 1. 4 2. 2 3. 6 4. 8 The answer is option(4). Explanation:Here the sizeof() operator enjoys the highest priority, which result in 4. But evaluation is not possible inside sizeof() operator. 4. What will be the output of the following? CPP #include <stdio.h> int main(void) { int a = 9; float x; x = a / 2; printf("%f", x); return 0; } Options: 1. 4.000000 2. 0 3. 4 4. No output The answer is option(1). Explanation: Here 9/2 which is 4. Then 4 is assigned to float and it becomes 4.000000. 5. What will be the output of the following? CPP #include <stdio.h> int main(void) { int a = 9; float x; x = (float)a / 2; printf("%f", x); return 0; } Options: 1. 4.000000 2. 4.50 3. 4 4. 4.500000 The answer is option(4). Explanation: With the help of type-casting we are able to get the exact result. Reference: https://www.geeksforgeeks.org/c/type-conversion-c/ Comment More infoAdvertise with us Next Article Output of C Programs | Set 5 B Bishal Dubey Improve Article Tags : C Language C-Output Similar Reads Output of C programs | Set 58 (operators) Prerequisite : Operators in C Q.1 What is the output of this program? CPP #include <iostream> using namespace std; int main() { printf("value is = %d", (10 ++)); return 0; } Options a) 10 b) 11 c) compile time error d) run time error ans: c Explanation : lvalue required as increment 3 min read Output of C programs | Set 49 (Operators) Prerequisite : Operators in C 1. What will be the output of the following program? CPP #include <stdio.h> int main(void) { int i = 40 >> 5 << 3 >> 2 << 1; printf("%d", i); return 0; } Options: 1. 4 2. 0 3. 40 4. 1 Answer : (1) Explanation: The answer is option 3 min read Output of C programs | Set 55 (Shift Operators) Prerequisite: Shift operators Q.1 What Is The Output Of this program? C #include <stdio.h> int main() { unsigned int i = 0x80; printf("%d ", i << 1); return 0; } Option a) 0 b) 256 c) 100 d) 80 ans :- b Explanation :- We know that 0x is hexa-decimal representation of number so 3 min read Output of C programs | Set 55 (Ternary Operators) Predict the output of below programs Question 1 C #include <stdio.h> int main() { int x, a = 0; x = sizeof(a++) ? printf("Geeks for Geeks\n") : 0; printf("Value of x:%d\n", x); printf("Value of a:%d", a); return 0; } Output: Geeks for Geeks Value of x:16 Value of 4 min read Output of C Programs | Set 5 Predict the output of below programs Question 1 c int main() { while(1){ if(printf("%d",printf("%d"))) break; else continue; } return 0; } Output: Can't be predictedExplanation: The condition in while loop is 1 so at first shot it looks infinite loop. Then there are break and con 5 min read Output of C programs | Set 55 1. What will be the output of the following program? C #include <stdio.h> int main() { int a = 03489; printf("%d", a); return (0); } Options: 1. 1865 2. runtime error 3. Syntax error 4. 0 The answer is option(3). Explanation: Any integral value prefix with 0 acts as octal number but 3 min read Like