#include <stdio.h>
main() {
int x = 65, *p = &x;
void *q = p;
char *r = q;
printf("%c", *r);
}
$x = 65$
In ASCII, $65 \equiv A$
Step 2: Pointer flow
$p = \&x \;\; \rightarrow$ pointer to integer
$q = p \;\; \rightarrow$ void pointer
$r = q \;\; \rightarrow$ typecast to char pointer
Step 3: Dereferencing
Since r is char*, it reads 1 byte.
The value stored = $65$
Step 4: Printing
printf("%c", *r); prints character with ASCII $65$.
Hence, the output is:
Correct Answer: (A)
a=10. Unary +a does not increment, it only returns the same value.ls -a.extern keyword is used in C to extend variable visibility across multiple files.x *= x + y means x = x * (x + y) ⇒ 2 * (2 + 1) = 6.5>8 is false ⇒ evaluate 1 != 2 < 5 ? 20 : 30.2<5 ⇒ 1. Then 1 != 1 ⇒ false ⇒ choose 30.if(a--) uses 1 (true) then decrements to 0 ⇒ prints "True".if(a++) tests 0 (false) then increments to 1 ⇒ no print.y (outside initialization),
so it will not compile. Hence, it gives a compilation error.What is the output of the following C program?
#include <stdio.h>
void main(){
int a = -7;
float b;
b = a++;
printf("%d, %f ", a, ++b);
}b = a++; assigns the current value of a (−7) to b and then increments a to −6.
Later, ++b increments b from −7 to −6 before printing.
$$ a = -6,\quad b = -6.000000 $$
What is the output?
#include <stdio.h>
void main(){
int i = -1;
printf("sizeof(i) = %d", sizeof(i));
}sizeof gives the size of the type in bytes, not the value.
On most 32-bit and 64-bit systems, sizeof(int) is 4.
$$ \text{Output: } \texttt{sizeof(i) = 4} $$
What is the output?
#include <stdio.h>
void main(){
int x = -1, y = 1, z = 0;
if(x && y++ && z)
++x, y++, --z;
printf("%d, %d, %d", x++, y++, z++);
}x && y++ && z, since z = 0, the logical AND short-circuits and the body of the if is not executed.
However, y++ is evaluated before the short-circuit, so y becomes 2.
Values before printing:
$$ x = -1,\ y = 2,\ z = 0 $$
So the program prints:
$$ (-1,\ 2,\ 0) $$
What is the output?
#include <stdio.h>
enum colors{RED, BROWN, ORANGE};
void main(){
printf("%ld..%f..%d", RED, BROWN, ORANGE);
}%f is used for int).
This causes undefined behavior.
The program may compile, but the output is not reliable.
Correct choice: None of these.
What is the output?
#include <stdio.h>
void main(){
char M = 'M';
printf("%d, %c", M, M);
}'M' has an ASCII value of 77.
So printing with %d shows 77, and %c shows M.
$$ \text{Output: } 77,\ M $$
What is the output?
#include <stdio.h>
void main(){
int i = -9;
printf("%d %d %d", i++, ++i, ++i);
}i par multiple modifications → C standard me undefined behavior.What is the output?
#include <stdio.h>
void main(){
int **ptr;
int temp = 65;
ptr[0] = &temp;
printf("%d", ptr[0][0]);
}ptr is uninitialized, so it does not point to valid memory.
When the code tries to access ptr[0], it attempts to dereference an invalid location.
This leads to undefined behavior, and in most cases results in a segmentation fault.
What is the output?
#include <stdio.h>
#include <stdlib.h>
void main(){
int *ptr;
ptr = (int*) calloc(3, sizeof(int));
ptr[2] = 30;
printf("%d", *ptr);
free(ptr);
}calloc initializes all allocated memory blocks with zero.
So ptr[0] is initialized to 0.
The statement *ptr is equivalent to ptr[0].
$$ \text{Output: } 0 $$
Explanation:
The variable var starts at 0.
The while (var < 10) loop prints 0 1 2 3 4 5 6 7 8 9 with spaces.
When var reaches 10, the loop stops.
After the loop, cout << var; prints 10.
Final output:
Explanation:
int Demo::count = 0; initializes the static variable count to 0.
Demo var1; → constructor is called once → count = 1.
Demo var2[5]; → constructor is called 5 times (for each element in the array) → count = 6.
Since count is static, it is shared among all objects.
Finally, cout << var1.count; prints 6.
? Correct answer: (A) 6 ✅
Explanation:
print() is declared as void print().
In main(), the statement var = print(); tries to assign the return value of print() to an int variable.
But since print() has no return value (void), this causes a compile-time error.
Hence, the program does not compile.
Explanation:
Initially var = 2.
First iteration: prints 2, then var-- makes var = 1.
Second iteration: prints 1, then var-- makes var = 0.
Third iteration: prints 0, then var-- makes var = -1. Condition fails and loop exits.
So output is:
Online Test Series,
Information About Examination,
Syllabus, Notification
and More.
Online Test Series,
Information About Examination,
Syllabus, Notification
and More.