Note 1

Take Note:

Take a note while surfing.





Note With Ink

Give your Note a Colorful Tag.




Easy to Access

Stay on same information and in Sync wherever you are.

Note 2

Take Note:

Organize your information,It may take Shape.





Think With Ink

Differ your Content by Color.




Easy to Access

Easy to pull up your content from anywhere anytime.

Note 3

Take Note:

Don't Let information to miss,Because it take shape





Note With Ink

Simple an Easy Way to take a note.




Easy to Access

Get the same in next visit.


Please wait...

C Programming :: Declarations and Initializations

1. What is the output of the following problem ?

#include
int main()
{
int i=4;
if(i=0)
printf("statement 1");
else
printf("statement 2");
return 0;
}

Answer: Option B

Explanation:

statement 1 will only be printed when i value=0. But i value is initialized as i=4 so it doesn't go with the first condition hence the second condition is accepted and statement 2 is printed.

Workspace


Tags:  No Tags on this question yet!

2. #include
int main() {
int i,j;
j = 10;
i = j++ - j++;
printf("%d %d", i,j);
return 0;
}

Answer: Option A

Explanation:

4th line of the program says j=10 . 5th line says j means post increment so after that line is executed j value will become 11 but during the execution of the 5th line j value is still 10 so i= 10-10=0



Now in the 5th line itself there has been two times increment of j so final value will be 12.



 

Workspace


Tags:  No Tags on this question yet!

3. int main()
{
int const * p=5;
printf("%d",++(*p));
return 0;
}

Answer: Option A

Explanation:

p is a pointer to a "constant integer". But we tried to change the value of the "constant integer".

Workspace


Tags:  No Tags on this question yet!

4. #include
#define max
int main(){
printf("%d",max);
return 0;
}

Answer: Option D

Explanation:

#define max(a,b) ((a).(b)?(a):(b)) This is the complete and correct way to define the function max . In the code its incomplete hence it shows compiler error.

Workspace


Tags:  No Tags on this question yet!

5. What is the output of the following 'C' program?

#include
void main() {
int x = 10,y = 10, z = 5, i;
i = x;
printf("%d",i==x);
}

Answer: Option A

Explanation:

The value of x initialised is 10. Also i=x so i=10. Now when comparing condition  (i==x) it will give boolean result that is if the condition is true it will return 1 else it will return 0. So here the condition is true coz x=i hence output is 1.



 

Workspace


Tags:  No Tags on this question yet!

6. What does the following 'C' program do ?

#include
void main()
{
unsigned int num;
int i;
scanf("%u", &num);
for (i = 0; i < 16; i++)
printf("%d", (num << i & 1 << 15)? 1:0);
}

Answer: Option B

Explanation:

Here integer (unsigned) is assumed as 2 bytes so that for loop is till 16 i.e (2byte = 16 bits.)

As unsigned integer so user is expected to enter positive number.

statement in printf (num << i & 1 << 15)? 1:0 is used to convert decimal to binary equivalent.

in the above statement below things has been used.

<< ----> left shift

& -----> And operator

? : ------> trinery operator

Ex: if the number is 10 and its binary equivalent 1010 or (00000000000001010 in 16 bit)

the printf statement will be

for i = 0

(10 << 0 & 1 << 15)>?1:0

for i = 1

(10 << 1 & 1 << 15)>?1:0

similarly for i = 2, 3, 4 , ---- 15

Workspace


Tags:  No Tags on this question yet!

7. What is the output of the following program ?

include
int main()
{
int x,y=2,z,a;
x = (y*=2) + (z=a=y);
printf ("%d", x);
return 0;
}

Answer: Option B

Explanation:

x = (y*=2) (z=a=y); Meaning of y*=2 means y=y*2 hence y value becomes 2*2=4. 



Current value of y =4 so z=a=y=4.



Hence x=4+4=8

Workspace


Tags:  No Tags on this question yet!

8. #include
void main()
{
int x,y=2,z,a;
if(x=y%2)
z=2;
a=2;
printf("%d %d",z,x);
}

Answer: Option D

Explanation:

The value of y%2 is 0. This value is assigned to x.
The condition will if (0) so z goes uninitialized.

Workspace


Tags:  No Tags on this question yet!

9. What is the output of the following 'C' program ?

#include
void fun(void)
{
static int s = 0;
s++;
if(s == 10)
return;
fun();
printf("%d ", s);
}

int main(void)
{
fun();
}

Answer: Option A

Explanation:

Here is no explanation for this answer

Workspace


Tags:  No Tags on this question yet!

10. What is the output of the following 'C' program ?

void main(){
char c=125;
c=c+10;
printf("%d",c);
}

Answer: Option C

Explanation:

Here char is signed so,the size of char is 1 bytes and its value range are -128 to 127,



and it will be something like below



-128 -127 -126 .......... 0 ....... 126 127 in the cycle. 



Now as per questions c = 125 it is under the above limit.



but when 10 added to it, it becomes 125 10 = 135



125 126 127 -128 -127 -126 -125 -124 -123 -122 -121 



So, count above 135 will fall at -121, so Answer will be -121



If in the question it would have given unsigned char then answer will be 135

Workspace


Tags:  No Tags on this question yet!



Most Popular Qs.

Latest MCQ Qs.