C Programming Multiple Choice Question - Printf & Scanf

This section focuses on the "Printf And Scanf" of the C programming. These Multiple Choice Questions (mcq) should be practiced to improve the C programming skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.

1. What is the output of this program?

#include <stdio.h>
int main()
{
	printf("variable! %d", x);
    return 0;
}

A. variable! x
B. variable! followed by a junk value
C. Compile time error
D. variable!

View Answer


2. What is the output of this program?

#include <stdio.h>
int main()
{
    int main = 3;
    printf("%d", main);
    return 0;
}

A. 3
B. Compile time error
C. Run time error
D. give garbage value

View Answer


3. What is the output of this program? if input a is 1 and b is 2

#include <stdio.h>
int main()
{
    int a, b;
    printf("%d", scanf("%d %d",&a,&b));
    return 0;
}

A. 1
B. 2
C. runtime error
D. compile time error

View Answer


4. What is the output of this program?

#include <stdio.h>
void main()
{
    printf("hello\rworld\n");
    printf("hello\b\b\bworld\n");
}

A. hello
helloworld
B. world
heworld
C. helloworld
hellold
D. None of the mentioned

View Answer


5. What is the output of this program?

#include <stdio.h>
int main()
{
    int i;
    i = printf("letsfindcourse");
    i = printf("%d ", i);
    printf("%d ", i);
    return 0;
}

A. letsfindcourse 15 3
B. letsfindcourse 14 2
C. letsfindcourse 14 3
D. Compilation Error

View Answer


6. Output of this statment is :

 
printf ( "%d" , printf ( "hello" ) );

A. Syntex Error
B. hello5
C. gives garbage value
D. print hello and terminates

View Answer


7. What is the output of this program?

#include <stdio.h>
# define scanf  "%s Find best course "
main()
{
   printf(scanf, scanf);
   return 0;
}

A. %s Find best course Find best course
B. %s Find best course %s Find best course
C. Invalid Syntex
D. Run time error

View Answer


8. Which statment is true about the given code ?

#include <stdio.h>
int main()
{
  printf("%d", main);
  return 0;
}

A. Goes in infinite loop
B. Gives Address of function main.
C. Gives garbage value
D. Compilation Error

View Answer


9. What is the output of this program?

#include <stdio.h>
int main()
{
    int i;
    i = 1, 2, 3;     
    printf("%d", i);
    return 0;
}

A. 1
B. 2
C. 3
D. Invalid Syntax

View Answer


10. Comment on the given statment:

scanf("%d",i);

A. Will execute without any error
B. Will give Segmentation fault
C. Will give Compilation Error
D. None of the above

View Answer


11. What is the output of this program?

#include <stdio.h>
int main()
{
    int x = 1, y = 2;
    printf("%d", x, y);
    return 0;
} 

A. 1
B. 2
C. Compilation Error
D. Garbage Value

View Answer


12. What is the output of this program?

#include <stdio.h>
int main()
{
    int x = 1, y = 2;
    printf("%*d", x, y);
    return 0;
}

A. 1
B. 2
C. Compilation Error
D. Garbage Value

View Answer


13. What is the output of this program?

#include <stdio.h>
int main()
{
    char str[25];
    printf(" %d ",printf("c-letsfind"));
    return 0;
}

A. 10 c-letsfind
B. 9 c-letsfind
C. c-letsfind 9
D. c-letsfind 10

View Answer


14. What is the output of this program?

#include <stdio.h>
# define loop while(true)
int main()
{
    loop;
    printf("c-letsfind");
    return 0;
}

A. program never ends
B. c-letsfind
C. Compilation error
D. None of the above

View Answer


15. What is the output of this program?

#include <stdio.h>
int main()
{
   printf("%d", 5.00);
   return 0;
}

A. Compilation error
B. Garbage value
C. 5
D. 0

View Answer


16. What is the output of this program?

#include <stdio.h>
int main()
{
  printf("%d",5.25);
   return 0;
}

A. Compilation error
B. Garbage value
C. 5
D. 0

View Answer


17. What is the output of this program ?

#include <stdio.h>
int main()
{
  int a = 3;
  printf("%d");
   return 0;
}

A. 3
B. Compilation error
C. Garbage value
D. Runtime error

View Answer


18. What is the output of this program ?

#include <stdio.h>
int main()
{
  char *ptr = "Hello World";
  printf(ptr+2);
   return 0;
} 

A. pointer cannot be initialized
B. lo World
C. Runtime error
D. llo World

View Answer


19. What is the output of this program 32 bit c compiler ?

#include <stdio.h>
int main()
{
  int a = 1;
  printf("%d %p",a,a);
   return 0;
}

A. Runtime error
B. 1 00000001
C. 1 1
D. %p is not a format specifier

View Answer


20. What is the output of this program ?

#include <stdio.h>
static struct student
{
  int a;
  int b;
}
  struct_var{2,3};
int main()
{
  printf("%d %d",struct_var.a,struct_var.b);
  return 0;
}

A. Runtime Error
B. Improper representation of structure variable
C. Compilation error
D. 2 3

View Answer


21. What is the output of the following code?

int main() {
  int i=1;
  i=2+2*i++;
  printf("%d",i);
  return 0;
}

A. 2
B. 3
C. 4
D. 5

View Answer


22. What is the output of the following code?

main ( ) 
{
 int i;
 i=1;
 i=i+2*i++;
 printf( "%d" , i);
}

A. 2
B. 3
C. 4
D. 5

View Answer


23. What is the output of this program?

main()
{
 int i;
 i = 2+3, 4>3, 1;
 printf( "%d" , i);
}

A. 1
B. 4
C. 3
D. 5

View Answer


24. What is the output of this program?

main ()
{
 int i=5;
 printf( "%d %d %d " , i,i<<2,i>>2);
}

A. 5 20 1
B. 5 1 20
C. 5 20 20
D. 5 1 1

View Answer


25. What is the output of this program?

main ( )
{
 int i=5;
 printf( "%d %d %d " , i,i<<2,i<<2);
}

A. 5 20 1
B. 5 1 20
C. 5 20 20
D. 5 1 1

View Answer


26. What is the output of this program?

int main()
{
    int i=5;
    printf( "%d %d %d " , i,i<2,i>2);
    return 0;
}

A. Compilation error
B. Garbage value
C. 5 0 1
D. 5 1 0

View Answer


27. What is the output of this program ?

int main()
{
  int i=5;
  printf( "%d %d %d " , i,i&&2,i||2);
  return 0;
}

A. 5 1 1
B. Compilation error
C. Garbage value
D. 5 0 1

View Answer


28. What is the output of this program ?

int main()
{
 int i=5;
 printf( "%d %d 
" , i,i|2);
 return 0;
}

A. 5 7
B. 5 1
C. Garbage value
D. 5 0

View Answer


29. What is the output of this program 32 bit c compiler ?

int main()
{
  int i=1;
  i=i+i*i++;
  printf("%d",i);
  return 0;
}

A. 2
B. 3
C. 4
D. 5

View Answer


30. What is the output of this program ?

int main()
{
  int i=-2;
  i=i+i*i++;
  printf("%d",i);
  return 0;
}

A. -2
B. 1
C. -1
D. -2

View Answer


31. What is the output of the following code?

int main()
{
    int k=1;
    printf("%d == 1 is" "%s", k, k==1?"TRUE":"FALSE");
    return 0;
}\

A. k == 1 is TRUE
B. 1 == 1 is TRUE
C. 1 == 1 is FALSE
D. K == 1 is FALSE

View Answer


32. What is the output of the following code?

int main()
{
    int k=2;
    printf("%d == 1 is" "%s", k, k==1?"TRUE":"FALSE");
    return 0;
}

A. k == 1 is TRUE
B. 2 == 1 is TRUE
C. 2 == 1 is FALSE
D. K == 1 is FALSE

View Answer


33. What is the output of this program?

char *str = "char *str = %c%s%c; main(){ printf(str, 4, str, 4);}";
int main()
{
    printf(str, 4, str, 4);
    return 0;
}

A. char *str = "char *str = %c%s%c; main(){ printf(str, 4, str, 4);}"; main(){ printf(str, 4, str, 4);}
B. char *str = %c%s%c; main(){ printf(str, 4, str, 4);}
C. No output
D. Error in program

View Answer


34. What is the output of this program?

main ( )
{
     float a=4.1589;
    printf("%2.3f", a);
    return 0;
}

A. 4
B. 4.159
C. 4.2
D. 4

View Answer


35. What is the output of this program?

main ( )
{
     float a=4.1589;
    printf("%2.1f", a);
    return 0;
}

A. 4
B. 4.1
C. 4.2
D. 4

View Answer


36. What is the output of this program?

int main()
{
   printf("%c", ~('C'*-1));
   return 0;
}

A. A
B. B
C. C
D. D

View Answer


37. What is the output of this program?

int main()
{
   printf("%c", ~('W'*-1));
   return 0;
}

A. S
B. T
C. U
D. V

View Answer


38. What is the output of this program ?

int main()
{
    char *p;
    p="%d";
    p++;
    p++;
    printf(p-2, 13);
    return 0;
}

A. 11
B. 13
C. Error
D. No output

View Answer


39. What is the output of this program 32 bit c compiler ?

int main()
{
     printf("%%%%");
    return 0;
}

A. %%%%%
B. %%
C. No output
D. Error

View Answer


40. What is the output of this program ?

int main()
{
     int a=250;
    printf("%1d<0x1d>", a);
    return 0;
}

A. 1250
B. 2
C. 50
D. 250

View Answer






Also check :


Discussion



* You must be logged in to add comment.