C Input and Output

Last Updated :
Discuss
Comments

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

Which of the following is the standard input stream in C?

  • stdout

  • Runtime error

  • stdin

  • stdfile

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;
}


  • 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

"Why is the & (address-of) operator used with scanf() when reading integer values?

  • To specify the format of the input.

  • To store the input at the variable’s memory address.

  • To perform pointer arithmetic.

  • It is optional and does not affect the function’s behavior.

Tags:

There are 37 questions to complete.

Take a part in the ongoing discussion