Wednesday, 28 February 2018

C interview question 8

What will be the output of the given code?

#include <stdio.h>

int main(void) {
 
 float a = 3.14;
 
 printf("%f",a%3);
 
 return 0;
}

Ans: Error


Reason: 
The modulus operator requires int type of data for it's operation.
Here we are giving one float data and other is integer data so the output will be an error.

Tuesday, 27 February 2018

C interview question 7

What will be the output of the given code?

#include <stdio.h>

int main(void)
{
char c='D';
printf ("%c",c+1);
return 0;
}

Output:
E
Reason:
Char c will store the ASCII value of D
When you print C+1 the next char to D that is E is being printed in the output.

Monday, 26 February 2018

C interview question 6

What will be the output of the given code?

void main()
{
int i=1;
i=!i>2;
printf ("i=%d",i);
}
Ans: 0


Reason:
!1 will be 0 [Because of precedence of operator, ! Operator has more precedence than the > operator]
0 is compared with 2
Condition  greater than fails
So the value of i will be 0

Sunday, 25 February 2018

C interview question 5

What will the output of the given code?
#include<stdio.h>
void main ()
{
int a=3;
a = ++a + ++a;
printf ("a=%d",a);
}

Ans:10


Reason:
Here pre-increment operator is used so the value of a is increased to 4 again another pre-increment operator which increases the value of a to 5 , then the value of a is added and assigned to a .
a    =   ++a    +    ++a;
  a=3
 ++a=4
 ++a=5
 a = 5 + 5;
 a = 10;



Friday, 23 February 2018

C interview question 4

What will be the output of the given code?

#include <stdio.h>

void main()

{
  int a;

  a=9;

  a=printf("Dcoder")+printf("Blog");

  printf("%d",a);

}



Reason:
The return type of printf() is integer and which is being added and assigned to "a" then the value of a is displayed along with the previous outputs printf().

Thursday, 22 February 2018

C interview question 3.


What will the output of the given code ?

void main()
{

int a=3;

a=printf ("Dcoder\n");

printf ("%d",a);

}

Output:
Dcoder
7

Reason:

Return type of printf() function is integer .

It prints Dcoder then return value of printf() is assigned to a , then prints the value of a i.e.7
printf () considers "\n" also so the value is 7.

C interview question 8

What will be the output of the given code? #include <stdio.h> int main(void) { float a = 3.14; printf("%f",a%3); ...