What is the difference between the following 2 codes? #include //Program 1 int main() { int d, a = 1, b = 2; d = a++ + ++b; printf("%d %d %d", d, a, b); }
#include //Program 2 int main() { int d, a = 1, b = 2; d = a++ +++b; printf("%d %d %d", d, a, b); }
No difference as space doesn’t make any difference, values of a, b, d are same in both the case
Space does make a difference, values of a, b, d are different
Program 1 has syntax error, program 2 is not
Program 2 has syntax error, program 1 is not
What will be the output of the following C code? #include int main() { int a = 1, b = 1, c; c = a++ + b; printf("%d, %d", a, b); }
a = 1, b = 1
a = 2, b = 1
a = 1, b = 2
a = 2, b = 2
What will be the output of the following C code?
#include int main() { int a = 1, b = 1, d = 1; printf("%d, %d, %d", ++a + ++a+a++, a++ + ++b, ++d + d++ + a++); }
15, 4, 5
9, 6, 9
9, 3, 5
Undefined (Compiler Dependent)
For which of the following, “PI++;” code will fail?
#define PI 3.14
char *PI = “A”;
float PI = 3.14;
none of the Mentioned
What will be the output of the following C code?
#include int main() { int a = 10, b = 10; if (a = 5) b--; printf("%d, %d", a, b--); }
a = 10, b = 9
a = 10, b = 8
a = 5, b = 9
a = 5, b = 8
What will be the output of the following C code? #include int main() { int i = 0; int j = i++ + i; printf("%d\n", j); }
0
1
2
Compile time error
What will be the output of the following C code?
#include int main() { int i = 2; int j = ++i + i; printf("%d\n", j); }
6
5
4
Compile time error
What will be the output of the following C code?
#include int main() { int i = 2; int i = i++ + i; printf("%d\n", i); }
= operator is not a sequence point
++ operator may return value with or without side effects
it can be evaluated as (i++)+i or i+(++i)
= operator is a sequence point
What will be the output of the following C code?
#include int main() { int i = 0; int x = i++, y = ++i; printf("%d % d\n", x, y); return 0; }
0, 2
0, 1
1, 2
Undefined
What will be the output of the following C code?
#include int main() { int i = 10; int *p = &i; printf("%d\n", *p++); }
10
11
Garbage value
Address of i
What will be the output of the following C code?
#include void main() { int x = 97; int y = sizeof(x++); printf("X is %d", x); }
X is 97
X is 98
X is 99
Run time error
What will be the output of the following C code? #include void main() { int x = 4, y, z; y = --x; z = x--; printf("%d%d%d", x, y, z); }
3 2 3
2 3 3
3 2 2
2 3 4
What will be the output of the following C code?
#include void main() { int x = 4; int *p = &x; int *k = p++; int r = p - k; printf("%d", r); }
4
8
1
Run time error
What will be the output of the following C code?
#include void main() { int a = 5, b = -7, c = 0, d; d = ++a && ++b || ++c; printf("\n%d%d%d%d", a, b, c, d); }
6 -6 0 0
6 -5 0 1
-6 -6 0 1
6 -6 0 1
What will be the output of the following C code?
#include void main() { int a = -5; int k = (a++, ++a); printf("%d\n", k); }