What Is The Output of This C Code
What Is The Output of This C Code
int main()
{
int i = -5;
int k = i %4;//-5%4->-1
printf("%d\n", k);
}
B. -1
C. 1
D. None
2.
What is the output of this C code?
int main()
{
int i = 5;
int l = i / -4; // 5/-4 -> -1
int k = i % -4; // 5 % -4->1
printf("%d %d\n", l, k);
return 0;
}
B. -1 1
C. 1 -1
int main()
{
int i = 7;
i = i / 4;//7/4 -> 1
printf("%d\n", i);
return 0;
}
B. 1
C. 3
void main()
{
int x = 4 *5 / 2 + 9;//20/2+9//10+9->19
}
A. 6.75
B. 1.85
C. 19
D. 3
void main()
{
int x = 4.3 % 2;
printf("Value of x is %d", x);
}
A. Value of x is 1.3
B. Value of x is 2
C. Value of x is 0.3
6.
What is the output of this C code?
void main()
{
int y = 3;
int x = 7 % 4 * 3 / 2;//3*3/2->9/2->4
printf("Value of x is %d", x);
}
A. Value of x is 1
B. Value of x is 2
C. Value of x is 4
A. %, *, /, +, -
B. %, +, /, *, -
C. +, -, %, *, /
D. %, +, -, *, /
A. a *= 20;
B. a /= 30;
C. a %= 40;
D. a != 50;
10. Which of the following data type will throw an error on modulus operation(%)?
A. char
B. short
C. float
D. int
int main()
{
int a = 20;
double b = 15.6;
int c;
c = a + b;
printf("%d", c);
}
A. 35(c)
B. 36
C. 35.6
D. 30
int main()
{
int a = 20, b = 15, c = 5;
int d;
d = a == (b + c);
printf("%d", d);
}
A. 1
B. 40
C. 10
D. 5
13.
What is the output of this C code?
void main()
{
int x = 0;
if (x = 0)
printf("Its zero\n");
else
printf("Its not zero\n");
}
B. Its zero
D. None
void main()
{
int k = 8;
int x = 0 == 1 && k++;
printf("%d%d\n", x, k);
}
A. 0 9
B. 0 8(c)
C. 1 9
D. 1 8
A. 6
B. Junk value
D. 7
void main()
{
1 < 2 ? return 1: return 2;
}
A. returns 1
B. returns 2
C. varies
int main()
{
int x = 2, y = 2;
x /= x / y;
printf("%d\n", x);
return 0;
}
A. 2(c)
B. 1
C. 0.5
D. Undefined behaviour
21. What is the type of the below assignment expression if x is of type float, y is of type
int?
y = x + y;
A. Int(c)
B. float
D. double
A. 2
B. true
C. 1(c)
D. 0
A. c = 1;
B. c = 2;
C. c = 3;
D. c = 4;(c)
int main()
{
int a = 1, b = 2;
a += b -= a;
printf("%d %d", a, b);
}
A. 1 1
B. 1 2
C. 2 1
D. 2 2
26.
What is the output of this C code?
int main()
{
int a = 4, n, i, result = 0;
scanf("%d", &n);
for (i = 0;i < n; i++)
result += a;
}
A. Addition of a and n.
B. Subtraction of a and n.
D. Division of a and n.
A. a %= 10;
B. a /= 10;
C. a |= 10;
int main()
{
int c = 2 ^ 3;
printf("%d\n", c);
}
A. 1
B. 8
C. 9
D. 0
int main()
{
unsigned int a = 10;
a = ~a;
printf("%d\n", a);
}
A. -9
B. -10
C. -11
D. 10
31. What is the output of this C code?
int main()
{
int a = 2;
if (a >> 1)
printf("%d\n", a);
}
A. 0
B. 1
C. 2
D. No output
int main()
{
int i, n, a = 4;
scanf("%d", &n);
for (i = 0; i < n; i++)
a = a * 2;
}
B. No output(c)
D. bitwise exclusive OR
void main()
{
int x = 97;
int y = sizeof(x++);
printf("x is %d", x);
}
A. x is 97(c)
B. x is 98
C. x is 99
34.
What is the output of this C code?
void main()
{
int x = 4, y, z;
y = --x;//3
z = x--;//3 2
printf("%d%d%d", x, y, z);
}
A. 3 2 3
B. 2 2 3
C. 3 2 2
D. 2 3 3(c)
void main()
{
int x = 4;
int *p = &x;
int *k = p++;
int r = p - k;
printf("%d", r);
}
A. 4
B. 8
C. 1(c)
void main()
{
int a = 5, b = -7, c = 0, d;
d = ++a && ++b || ++c;
printf("\n%d%d%d%d", a, b, c, d);
}
A. 6 -6 0 0
B. 6 -5 0 1
C. -6 -6 0 1
D. 6 -6 0 1(c)
void main()
{
int a = -5;
int k = (a++, ++a); -5,-3
printf("%d\n", k);
}
A. -3(c)
B. -5
C. 4
D. Undefined
int main()
{
int x = 2;
x = x << 1;
printf("%d\n", x);
}
A. 4(c)
B. 1
int main()
{
int x = -2;
x = x >> 1;
printf("%d\n", x);
}
A. 1
B. -1(c)
A. Yes
B. No(c)
D. Undefined
int main()
{
int x = -2;
if (!0 == 1)
printf("yes\n");
else
printf("no\n");
}
A. Yes
B. No
D. Undefined
int main()
{
int y = 0;
if (1 |(y = 1))
printf("y is %d\n", y);
else
printf("%d\n", y);
}
A. 1
B. 0
D. Y is 1(c)
#include <stdio.h>
int main()
int y = 1;
return 0;
A. true 2(c)
B. false 2
D. true 1
int main()
{
int a = 1, b = 1, c;
c = a++ + b;//1 + 1 =2 a=2
printf("%d, %d", a, b);
}
A. a = 1, b = 1
B. a = 2, b = 1
C. a = 1, b = 2
D. a = 2, b = 2
int main()
{
int a = 1, b = 1, d = 1;
printf("%d, %d, %d", ++a + ++a+a++, a++ + ++b, ++d + d++ + a++);
}
A. 15, 4, 5(c)
B. 9, 6, 9
C. 9, 3, 5
D. 6, 4, 6
48.
What is the output of this C code?
int main()
{
int a = 10, b = 10;
if (a = 5)
b--;
printf("%d, %d", a, b--);
}
A. a = 10, b = 9
B. a = 10, b = 8
C. a = 5, b = 9(c)
D. a = 5, b = 8
int main()
{
int i = 0;
int j = i++ + i;
printf("%d\n", j);
}
A. 0
B. 1(c)
C. 2
int main()
{
int i = 2;
int j = ++i + i;
printf("%d\n", j);
}
A. 6(c)
B. 5
C. 4