Beruflich Dokumente
Kultur Dokumente
#include<stdio.h>
int main()
charnum = '\010';
printf("%d", num);
return 0;
OUTPUT
A. 010 B. 08 C. 10 D. 8
Explanation
The value of a variable num is '\010'. Which means the character with value 10 in octal, which is 8 in
decimal.
#include<stdio.h>
int main()
void *ptr;
intnum = 10;
ptr = #
printf("%d", ptr);
return 0;
OUTPUT
Explanation
Though, void is not a valid data type for declaring variables. It is a valid for declaring pointer variable
*ptr thus printf displays the address of a normal variable num
#include<stdio.h>
int main()
void num=10;
printf("%v", num);
return 0;
OUTPUT
Explanation
#include<stdio.h>
int main()
printf("%d\t",sizeof(2.5));
printf("%d\t",sizeof(2));
printf("%d",sizeof('A'));
return 0;
OUTPUT
A. 8 4 2 B. 8 4 1 C. 4 4 1 D. 2.5 2 A
Explanation
C compiler by default will assign any undeclared float data type as double. Thus 8 4 1 is outputted.
int main(){
signed a;
unsigned b;
b = a + 1;
if(a == b)
printf("%d %d",a,b);
else
return 0;
OUTPUT
Explanation
Clearly, a != b and it execute the else part, where we ask compiler to display the value of a and b.
OUTPUT
Explanation
#include<stdio.h>
int main(){
float me = 5.25;
else
return 0;
OUTPUT
Explanation
For floating point numbers (float, double, long double) the values cannot be predicted exactly.
Depending on the number of bytes, the precession with of the value represented varies. Float takes
4 bytes and long double takes 10 bytes. So float stores 0.9 with less precision than long double.
#include<stdio.h>
int main()
externintnum;
num = 5;
printf("%d", num);
return 0;
OUTPUT
Explanation
extern is a C keyword which specifies to the compiler that the memory for num is allocated in some
other program and that address will be give to our current(this) program at the time of execution or
linking. Here extern intnum; is declared within the scope of the program.
#include<stdio.h>
int main(){
char *ptr;
return 0;
OUTPUT
A. 2 4 B. 4 4 C. 1 4 D. 1 2
Explanation
The sizeof() operator returns the number of bytes taken by its operand ptr.Here *ptr is the character
pointer which holds the memory byte of 1 and ptr is allocated with 4 bytes to hold the address of
the character pointer variable *ptr
#include<stdio.h>
int main(){
intnum = - -2;
return 0;
OUTPUT
Explanation
#include<stdio.h>
int main()
float a = 5.0;
OUTPUT
Explanation
#include<stdio.h>
int main()
10;
printf("%d", 10);
OUTPUT
Explanation
#include<stdio.h>
int main()
charnum = 127;
num = num + 1;
printf("%d", num);
return 0;
OUTPUT
A. garbage value B. Compilation error C. range out of bond D. -128
Explanation
Though a char is of ranging from -128 to 127. Whatever a integer number we are adding, it will loop
through out its range. Thus after 127 the number is -128.
#include<stdio.h>
int main()
printf("%d",++size);
return 0;
OUTPUT
Explanation
Volatile and const are C Keywords and their individual size is 4 bytes
#include<stdio.h>
int main()
staticintnum = 6;
printf("%d ",num--);
if(num)
main();
return 0;
OUTPUT
Simply, function is looping again and again till num becomes 0 to exit the if condition.
#include<stdio.h>
int main()
printf("yes");
else
printf("No");
return 0;
OUTPUT
Explanation
-12
-56
23
are assigned as unsigned integer by C compiler. So if negative integers are given it will loop through
its range 0 to 65,535.i.e) -12 is equal to 65524.
#include<stdio.h>
int main()
return 0;
}
OUTPUT: A
A. % B. No output C. %% D. %%%
Explanation
#include<stdio.h>
int main()
float x = 3.14;
double y = 3.14;
return 0;
OUTPUT
Explanation
#include<stdio.h>
int main()
staticintnum = 3;
if(--num)
main();
printf("%d ",num);
return 0;
OUTPUT
A. 2 1 B. 0 0 C. 1 1 D. 1 0
Explanation
A static variable num is shared among all calls of a function finally ended up with a output 0
Questions on Variables
#include<stdio.h>
int main()
printf("%d",1_one);
return 0;
Explanation
Invalid variable name. Variable name must begins with either alphabet or underscore( _ ).
#include<stdio.h>
int main(){
int default = 5, a = 3;
if(a > 2)
printf("%d",default);
return 0;
}
OUTPUT
Explanation
#include<stdio.h>
int main()
int class;
int public = 5;
printf("%d",class);
return 0;
OUTPUT:
EXPLANATION
C programming don't have any access specifier. Thus it is possible to use class, Public, Private and
Protected as a variable name.
#include<stdio.h>
int main()
int _int = 5;
printf("%d",_int);
return 0;
OUTPUT:
Explanation
Though int is a keyword, it is prefixed with underscore, this makes it possible to use _int as a variable
#include<stdio.h>
int main(){
int _ = 5;
int __=5;
printf("%d",___);
return 0;
OUTPUT
Explanation
#include<stdio.h>
staticnum=5;
externintnum;
int main()
printf("%d",num);
return 0;
OUTPUT
Explanation
#include<stdio.h>
staticnum=5;
externintnum=10;
int main()
printf("%d",num);
return 0;
OUPTUT
A. Compilation error B. 5 C. 0 D. 10
Explanation
Though global variables can have same name, but we can initialize only one of them.
#include<stdio.h>
int main()
int min-value = 2;
return 0;
OUTPUT
Explanation
Special characters are not allowed in declaring a variable name. In this case the special character is
min-value.
#include<stdio.h>
int main(){
structnum
intnum;
};
structnum key={25};
printf("%d",key.num);
return 0;
OUTPUT
Explanation
#include<stdio.h>
int main()
printf("%d",EOF);
return 0;
OUTPUT
EXPLANATION
In C, EOF - End of File which is a macro and its header file is stdio.h. In C, EOF is equal to -1 by
default. We can use EOF in some programs to check whether file pointer reaches the end of the file.
#include<stdio.h>
int main()
intscanf = 13;
printf("%d",scanf);
return 0;
OUTPUT
Explanation
scanf as a variable name is possible because we have not used it as function declaration(
intscanf()=13 ).
#include<stdio.h>
int main()
{
intprintf = 13;
int c = 7 + printf;
printf("%d",c);
return 0;
OUTPUT
Explanation
What's wrong with printf here and what's right with previous question scanf. Here we explain
printf can be declared as a variable, when to outputted the value stored in the printf variable, we
use printf() inbuilt function.
when we use printf() it will search for printf() function in our program, here we declared printf as a
variable and not as a function , thus it leads to compiletime error.
#include<stdio.h>
int main()
charprintf[25] = "printf";
puts(printf);
return 0;
OUTPUT
Explanation
As we explained in previous program, we used puts() instead of printf() in-built function. Thus there
is no problem with output.
14. What will be the output of the C program?
#include<stdio.h>
int main(){
int EOF = 0;
printf("%d",EOF);
return 0;
OUTPUT:
Explanation
In C, EOF is a predefined macro constant. We do not have any permission even to declare EOF as a
variable name. Then for sure we cannot declare or increment any values to EOF- End Of File
#include<stdio.h>
int main()
printf("%d",xyz);
return 0;
OUTPUT
Explanation
int xyz = 20; is a global variable, and int xyz = 40 is a local variable, Here we are calling xyz outside
the scope of xyz = 40. Thus it outputted 20.
#include<stdio.h>
int main()
printf("%d",xyz);
return 0;
OUTPUT
Explanation
#include<stdio.h>
int main(){
chararr[] = "Cat";
*arr = 'B';
printf("%s", arr);
return 0;
OUTPUT
Explanation
*arr = 'B' tells to compiler to replace the first letter of arr[] to 'B'. Thus Cat changes to Bat.
#include<stdio.h>
int main()
*ptr = 'B';
printf("%s", ptr);
return 0;
OUTPUT
Explanation
*ptr='B', trying to change the character at base address to 'C' of a constant string, which is
impossible and it leads to runtime error.
#include<stdio.h>
int main()
char arr1[50];
arr1 = arr2;
printf("%s", arr1);
return 0;
OUTPUT
Explanation
arr1 refers to base address and is constant. Hence lvalue required compile time error.
#include<stdio.h>
int main()
if(arr1 == arr2)
printf("cheers");
return 0;
OUTPUT
Explanation
Here we are comparing both base addresses and they never going to be same, hence No output.
#include<stdio.h>
int main()
printf("%u", sizeof(p));
printf("%u", sizeof(q));
return 0;
OUTPUT
Explanation
The size of pointer variable of any data type(char, int, double, float) will be 4 and are same.
#define num 10
int main()
#define num 50
printf("%d",num);
return 0;
OUTPUT
Explanation
The pre processor directives in c programming can be redefined anywhere in the program. So the
most recently assigned value will be outputted.
QUESTIONS ON OPERATORS
https://www.2braces.com/c-questions/operators-questions-c-1
#include<stdio.h>
int main()
intnum = 8;
return 0;
OUTPUT
A. 7 9 B. 4 16 C. 9 7 D. 16 4
Explanation
Shift operator shift the value stored in a variable num. One to the right(<<) and other to the left(>>).
int main()
int i = 5;
printf("%d",a);
return 0;
A. 14 B. 13 C. 12 D. 11
Explanation
actuallty a = 6 + 7;, but not because second (++) operators result will be overwritten to the first
operand.
Note that even if you have n number of operands with increment operator(++). the above discussed
effect will take place only between first and second operand. Please check next quiz to clear it 100%.
#include<stdio.h>
int main()
int i = 5;
printf("%d",a);
return 0;
A. 24 B. 23 C. 21 D. 22
Explanation
a = 6 + ++i + ++i
a = 6 + 7 + ++i
a = 7 + 7 + ++i
a=7+7+8
a=7+7+8
#include<stdio.h>
int main()
int i = 5;
printf("%d",a);
return 0;
A. 2 1 B.31 C. 1 1 D. 1 0
Explanation
a = 6 + 7 + ++i + ++i
a = 7 + 7 + ++i + ++i
a = 7 + 7 + 8 + ++i
a=7+7+8+9
#include<stdio.h>
int main(){
int i = 16;
i =! i> 15;
printf("i = %d",i);
return 0;
A. 16 B. 1 C. 0 D. Compilation error
Explanation
Note !i which means for any value of variable i to 0.
Now, we have the condition i = 0 > 14;. Thus i = 0 ( condition false ) will is outputted.
#include<stdio.h>
int main()
int i = 5;
printf("%d",a);
return 0;
A. 8 B. 5 C. 7 D. 6
Explanation
#include<stdio.h>
int main()
int i = 5;
printf("%d",a);
return 0;
A. 8 B. 9 C. 7 D. 6
Explanation
a = 4 + --i + --i
a = 4 + 3 + --i
a = 3 + 3 + --i
a=3+3+2
#include<stdio.h>
int main()
int i = 5;
printf("%d",a);
return 0;
A. -2 B. -3 C. -1 D. -4
Explanation
a = 4 - 3 - --i - --i
a = 3 - 3 - --i - --i
a = 3 - 3 - 2 - --i
a=3-3-2-1
#include<stdio.h>
int main()
int a = 2, b = 2, c = 0, d = 2, m;
return 0;
Explanation
m = 1 || d++;
m = 1 || 0;
m = 1;
#include<stdio.h>
int main()
int i = 5;
printf("%d",a);
return 0;
A. 7
B. 9
C. 8✔
D. 10
x
WoW you are Great
Option: C
Explanation
a = 4 + 5 - i-- + --i
a = 5 + 5 - 5 + --i
a=5+5-5+3
#include<stdio.h>
int main()
int a = 5;
a = 1, 2, 3;
printf("%d", a);
return 0;
A. 3 B. 5 C. compilation error D. 1
Explanation
Priority for the values assigned to any variable is given from left to right.
#include<stdio.h>
int main()
int a;
a = (1, 2, 3);
printf("%d", a);
return 0;
A. 8 B. 3 C. 7 D. 6
Explanation
Priority for the values inside a brackets () assigned to any variable is given from right to left.
#include<stdio.h>
int main()
printf("%d",sizeof(x));
return 0;
}
A. 2 B. 4 C. 20 D. 40
Explanation
Here x is an array variable which holds 10 integer values. Thus sizeofint is 4, then 4 * 10 = 40.
#include<stdio.h>
int main()
unsignedintnum = -4;
printf("%d", ~num);
return 0;
Explanation
the function of ~ is a One's Complement is to inverse all value only after converting a decimal value
to binary 0's and 1's
~num = 3
#include<stdio.h>
int main()
int x = 2;
return 0;
Explanation
As & is a unary operator we have to assume all decimal values to binary(0's and 1's)
int main()
int a = 4, b = 2;
return 0;
A. 12 B. 10 C. 8 D. 6
Explanation
#include<stdio.h>
int main()
int a = 4, b = 2;
return 0;
A. 6 B. 7 C. 5 D. 4
Explanation
#include<stdio.h>
int main()
int a = 7, b = 4, c = 2;
return 0;
}
A. 3 B. 8 C. 6 D. 7
Explanation
a = 7 which is 0111
b = 4 which is 0100
c = 2 which is 0010
0111|0000.
#include<stdio.h>
int main()
printf("%d",c);
return 0;
}
Explanation
#include<stdio.h>
int main()
printf("%d",a);
return 0;
Explanation
0 - 1 = -1
#include<stdio.h>
int main()
printf("%d",3 * 2--);
}
A. 3 B. 9 C. 6 D. Compilation error
Explanation
#include<stdio.h>
int main()
int a = 1, b = 3, c;
c = b << a;
b = c * (b * (++a)--);
a = a >> b;
printf("%d",b);
return 0;
A. 36 B. Compilation error C. 30 D. 24
Explanation
c = 3 >> 1;
c = 0011 << 1;
c = 0110;
c=6
b = c * (b * (++a)--);
b = 6 * (3 * (2)--);
b = 6 * 6( post -- is neglected in this case)
b = 36 which is outputted.
#include<stdio.h>
int main()
int i = 10;
i++;
i * i;
printf("%d\n",i);
return 0;
A. 121 B. 100 C. 10 D. 11
Explanation
#include<stdio.h>
int main()
struct bb
return 0;
Explanation
Initialization for structure members should not be done inside the structure declaration itself.
#include<stdio.h>
#define x =
int main()
int a;
a x 5;
printf("%d",a);
return 0;
Explanation
= is defined in proprocessor with the name of x. Thus no problem with a normal compilation flow.
#include<stdio.h>
int x = 0;
int main(){
if(x == x)
else
return 0;
A. hai this is if B. hai this is else C. prints nothing D. Compile Time Error
Explanation
This program will print the statement inside the if block because if statement just compare two
values(0 == 0, condition is true) and returns 1(true). So the statement inside if block is executed.
#include<stdio.h>
#define FALSE -1
#define NULL 0
#define TRUE 1
int main(){
if(NULL)
printf("NULL");
else if(FALSE)
printf("TRUE");
else
printf("FALSE");
return 0;
Explanation
The if block will be executed if the condition returns a non-zero value. In the above program,
if(NULL) is appears like if(0), here the condition is false. Then else if(FALSE) is appears like else if(-1),
here it has a non-zero value so the else if block is executed.
#include<stdio.h>
int main(){
int i = 0, j = 0;
if(i++ == j++)
else
return 0;
A. 0 0 B. 0 1 C. 1 0 D. 1 1
Explanation
In the above program, the if(i++ == j++) is appears like if(0 == 0), condition is true. So the if block gets
executed.
int main(){
int i = 0, j = 1, k = 0;
if(++k, j, i++)
return 0;
Explanation
In the above program, the if(++k, j, i++) will appears like if(1, 1, 0) consider this as (expression1,
expression2, expression3), in this context, first expression1 is evaluated, expression2 is evaluated,
then expression3 is evaluated, and the value of expression3 is returned for the whole expression. As
a result the condition is false. So it will prints nothing.
#include<stdio.h>
int main(){
int i;
if(true)
else
return 0;
A. This will work B. This will not work C. Compilation Error D. Runtime Error
Explanation
Error: Undefined symbol 'true'.
The above C program will prints error message because C programming does not support the
keyword 'true' and 'false'.
#include<stdio.h>
int main()
else
return 0;
A. if block executed B. else block executed C. Compilation Error D. None of the above
Explanation
#include<stdio.h>
int main()
charstr[] = "\0";
if(printf("%s",str))
printf("inside if block");
else
printf("inside else block");
return 0;
Explanation
In the above C program, the printf statement or expression inside if block prints nothing. So the
expression returns 0 and else block gets executed.
#include<stdio.h>
int main()
if(printf("0"))
printf("inside if block");
else
return 0;
A. inside if block B. inside else block C. 0inside else block D. 0inside if block
Explanation
The printfstatement inside if block prints 0, so the expression returns 1. Finally the if block gets
executed.
#define NULL 0
int main()
if(printf("0") == NULL)
printf("inside if block");
else
return 0;
A. 0inside if block B. 0inside else block C. inside else block D. inside if block
Explanation
The if statement compares two expressions and returns a result. We can consider the if(printf("0")
== NULL) as if(expression1 == expression2). The expression1(printf("0") prints 0) returns 1 and
expression2 is 0. So the condition is false and else block will be executed.
#include<stdio.h>
int main(){
int i = 5, j = 4;
if(!printf(""))
else
return 0;
A. 6 5 B. 5 5 C. 5 4 D. 6 4
Explanation