• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

C Input and Output

Question 1

Predict the output of the below program:

C
#include <stdio.h>

int main()
{
    printf(\"%c \", 5[\"GeeksQuiz\"]);
    return 0;
}
  • Compile-time error

  • Runtime error

  • Q

  • s

Question 2

Predict the output of below program: C
#include <stdio.h>
int main()
{
    printf(\"%c \", \"GeeksQuiz\"[5]);
    return 0;
}
  • Compile-time error
  • Runtime error
  • Q
  • s

Question 3

Which of the following is true
  • gets() can read a string with newline characters but a normal scanf() with %s can not.
  • gets() can read a string with spaces but a normal scanf() with %s can not.
  • gets() can always replace scanf() without any additional code.
  • None of the above

Question 4

C
#include<stdio.h>

int main()
{
    char *s = \"Geeks Quiz\";
    int n = 7;
    printf(\"%.*s\", n, s);
    return 0;
}
  • Geeks Quiz
  • Nothing is printed
  • Geeks Q
  • Geeks Qu

Question 5

Predict the output of following program? C
#include <stdio.h>
int main(void) 
{
   int x = printf(\"GeeksQuiz\");
   printf(\"%d\", x);
   return 0;
}
  • GeeksQuiz9
  • GeeksQuiz10
  • GeeksQuizGeeksQuiz
  • GeeksQuiz1

Question 6

Output of following program? C
#include<stdio.h>
int main()
{
    printf(\"%d\", printf(\"%d\", 1234));
    return 0;
}
  • 12344
  • 12341
  • 11234
  • 41234

Question 7

What is the return type of getchar()?
  • int
  • char
  • unsigned char
  • float

Question 8

Normally user programs are prevented from handling I/O directly by I/O instructions in them. For CPUs having explicit I/O instructions, such I/O protection is ensured by having the I/O instructions privileged. In a CPU with memory mapped I/O, there is no explicit I/O instruction. Which one of the following is true for a CPU with memory mapped I/O?
  • I/O protection is ensured by operating system routine (s)
  • I/O protection is ensured by a hardware trap
  • I/O protection is ensured during system configuration
  • I/O protection is not possible

Question 9

Consider the following C - code :
C
#include \"stdio.h\"

int foo(int a)
{
 printf(\"%d\",a);
 return 0;
}

int main()
{
 foo;
 return 0;
}
Which of the following option is correct?
  • It’ll result in compile error because foo is used without parentheses.
  • No compile error and some garbage value would be passed to foo function. This would make foo to be executed with output “garbage integer”.
  • No compile error but foo function wouldn’t be executed. The program wouldn\'t print anything.
  • No compile error and ZERO (i.e. 0) would be passed to foo function. This would make foo to be executed with output 0.

Question 10

Which of the following functions from “stdio.h” can be used in place of printf()?
  • fputs() with FILE stream as stdout.
  • fprintf() with FILE stream as stdout.
  • fwrite() with FILE stream as stdout.
  • All of the above three - a, b and c.
  • In “stdio.h”, there’s no other equivalent function of printf().

There are 37 questions to complete.

Last Updated :
Take a part in the ongoing discussion