0% found this document useful (0 votes)
8 views

Data Types and Operator _ DPP 02

The document contains a set of programming questions related to C programming, specifically focusing on data types and operators. Each question is followed by multiple-choice answers, and the document includes an answer key along with detailed solutions explaining the output of the code snippets provided. The questions test the understanding of concepts such as increment/decrement operators, bitwise operations, and logical expressions.

Uploaded by

gravityingalaxy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Data Types and Operator _ DPP 02

The document contains a set of programming questions related to C programming, specifically focusing on data types and operators. Each question is followed by multiple-choice answers, and the document includes an answer key along with detailed solutions explaining the output of the code snippets provided. The questions test the understanding of concepts such as increment/decrement operators, bitwise operations, and logical expressions.

Uploaded by

gravityingalaxy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

1/17/25, 6:12 PM GATE_Computer Science & Information Technology_DPP 2

GATE

Computer Science & Information Technology


C - Programming
DPP: 2
Data Types & Operators

Q1 What will be the output of the following code? return 0;


#include <stdio.h> }
int main() { (A) 90 (B) 30
int x = 10, y=10, z=20; (C) 91 (D) 31
y = x++ + ++y + --z;
Q4 What will be the output of the following code?
printf("%d\n", y);
#include <stdio.h>
return 0;
int main()
}
{
(A) 40 (B) 31
unsigned int a = 45, b = 35;
(C) 32 (D) 33
int result = (a & b) | (a ^ b);
Q2 #include <stdio.h> printf("%d\n", result);
int main() return 0;
{ }
int x =12, y, b=24; (A) 43 (B) 45
y = x++; (C) 47 (D) 49
y = ++x;
Q5 Consider the following code snippet:
y = x++*b;
#include <stdio.h>
y = x--;
int main()
y = --x;
{
y = x--*b;
unsigned int x = 7, y = 25;
y = --x*b;
int result = ~(x << 2) & (y >> 2);
printf("%d",x+y);
printf("%d\n", result);
return 0;
return 0;
}
}
The output of the program is _______
What is the output?
Q3 What will the following code print? (A) 2 (B) 6
#include<stdio.h> (C) 7 (D) 8
int main () {
Q6 What will be the result of the following code?
int m=90, k=30;
#include <stdio.h>
int n, n1;
int main()
n=++m + ++k;
{
n1=m-- + --k ;
int a = 100, b = 45;
n--;
int result = (a ^ b) << 3;
--n1;
printf("%d\n", result);
n-=n1;
return 0;
printf("%d", n+k);

Android App | iOS App | PW Website

https://qbg-admin.penpencil.co/finalize-question-paper/print-preview 1/5
1/17/25, 6:12 PM GATE_Computer Science & Information Technology_DPP 2

GATE

} }
(A) 440 (B) 360
Q9 Consider the following code snippet:
(C) 584 (D) 784
#include <stdio.h>
Q7 Consider the following code: int main()
#include <stdio.h> {
int main() int x = 5, y = 10;
{ int result = (x > 3 && y < 20) || (x++ > 5);
unsigned int x = 34, y = 15; printf("%d %d\n", result, x);
int result = (x & y) ^ (x | y); return 0;
printf("%d\n", result); }
return 0; What is the output of the program?
} (A) 15 (B) 05
What will be the output of the program? (C) 16 (D) 06
(A) 15 (B) 30
Q10 What will the following code output?
(C) 45 (D) 60
#include <stdio.h>
Q8 What will be the output of the following code ? int main()
#include <stdio.h> {
int main() int a = 4, b = -3, c = 0;
{ int result = a || b && c;
int a = 10, b = 0, c = – 5; printf("%d\n", result);
int result = a && b || c; return 0;
printf("%d\n", result); }
return 0;

Android App | iOS App | PW Website

https://qbg-admin.penpencil.co/finalize-question-paper/print-preview 2/5
1/17/25, 6:12 PM GATE_Computer Science & Information Technology_DPP 2

GATE

Answer Key
Q1 (A) Q6 (C)

Q2 275 Q7 (C)

Q3 (D) Q8 1

Q4 (C) Q9 (A)

Q5 (A) Q10 1

Android App | iOS App | PW Website

https://qbg-admin.penpencil.co/finalize-question-paper/print-preview 3/5
1/17/25, 6:12 PM GATE_Computer Science & Information Technology_DPP 2

GATE

Hints & Solutions


Q1 Text Solution: positions, which shifts the binary value of 73
The initial values are x = 10, y = 10, and z = 20. In (01001001) to 584 (01001001000). Therefore,
the expression y = x++ + ++y + --z, x++ evaluates the final result of the expression is 584. The
to 10 (then x becomes 11), ++y becomes 11, and -- program prints 584
z becomes 19. Substituting these values, the Q7 Text Solution:
expression becomes y = 10 + 11 + 19, resulting in y initially, x = 34 and y = 15, and the expression
= 40. The program prints 40, so the correct result = (x & y) ^ (x | y) is evaluated. The bitwise
option is A. 40.
AND of x and y results in 2, while the bitwise OR
Q2 Text Solution: of x and y gives 47. Next, the XOR operation
Initially the program stores the values x = 12 and between 2 and 47 produces 45. Therefore, the
b = 24. Through various operations, x is final result of the expression is 45. The program
incremented and decremented, while y is prints 45.
calculated as follows: after y = --x * b, the final Q8 Text Solution:
value of y becomes 264, and x is 11. Substituting
initially value of a = 10, b = 0, and c = -5, and
these values into printf("%d", x + y), we get x + y =
evaluates the expression result = a && b || c. First,
11 + 264 = 275. Hence, the program outputs 275.
the logical AND (a && b) is evaluated. Since a is
Q3 Text Solution: non-zero (true) and b is zero (false), the result of
Iniatally, m = 90 and k = 30. After evaluating n = a && b is false (0). Next, the logical OR (||) is
++m + ++k, we get n = 122, and after n1 = m-- + --k, evaluated with c. As c is -5 (non-zero, true), the
n1 = 121. The subsequent decrements make n = 1 result of b || c becomes true (1). Therefore, the
and n1 = 120, and n -= n1 results in n = 1. Finally, n final value of result is 1. The program prints 1.
+ k = 1 + 30 = 31, so the program prints 31.
Q9 Text Solution:
Q4 Text Solution: in the start , program initializes x = 5 and y = 10,
Initially, a = 45 and b = 35, and evaluates the and the expression result = (x > 3 && y < 20) ||
expression result = (a & b) | (a ^ b). The bitwise (x++ > 5) is evaluated. First, the condition (x > 3
AND (a & b) results in 33, and XOR (a ^ b) results && y < 20) is checked. Since x > 3 (true) and y <
in 14. The OR operation on these (33 | 14) gives 20 (true), the entire condition evaluates to true
47. Therefore, the program prints 47. (1). Due to the short-circuiting property of the ||
(OR) operator, the second condition (x++ > 5) is
Q5 Text Solution:
not evaluated because the first condition is
Initially, x = 7 and y = 25, and the expression
already true. As a result, the value of x remains
result = ~(x << 2) & (y >> 2) is evaluated. First, x <<
unchanged at 5. The final value of result is 1. The
2 results in 28, and its bitwise NOT gives -29.
program prints 1 5.
Then, y >> 2 results in 6. The bitwise AND
between -29 and 6 gives the final result 2. Q10 Text Solution:
Therefore, the program prints 2. Initially, a = 4, b = -3, and c = 0. The expression
result = a || b && c is evaluated based on
Q6 Text Solution:
operator precedence, where logical AND (&&) is
given, a = 100 and b = 45, then calculates result =
evaluated before logical OR (||). First, b && c is
(a ^ b) << 3. The bitwise XOR of a and b results in
evaluated. Since b = -3 (true) and c = 0 (false), the
73. Then, the result (73) is left-shifted by 3
result of b && c is false (0). Next, the logical OR is

Android App | iOS App | PW Website

https://qbg-admin.penpencil.co/finalize-question-paper/print-preview 4/5
1/17/25, 6:12 PM GATE_Computer Science & Information Technology_DPP 2

GATE

evaluated as a || 0. Since a = 4 (true), the final program prints 1.


result of the expression is true (1). Therefore, the

Android App | iOS App | PW Website

https://qbg-admin.penpencil.co/finalize-question-paper/print-preview 5/5

You might also like