• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

50 C Language MCQs with Answers

Question 31

The value printed by the following program is
 

C
void f(int* p, int m)
{
    m = m + 5;
    *p = *p + m;
    return;
}
void main()
{
    int i=5, j=10;
    f(&i, j);
    printf(\"%d\", i+j);
}
  • 10
     

  • 20
     

  • 30
     

  • 40
     

Question 32

Pick the best statement for the following program snippet: 
 

C
#include <stdio.h>

int main()
{
 int var;  /*Suppose address of var is 2000 */

 void *ptr = &var;
 *ptr = 5;
 printf(\"var=%d and *ptr=%d\",var,*ptr);
             
 return 0;
}
  • It will print “var=5 and *ptr=2000”
     

  • It will print “var=5 and *ptr=5”
     

  • It will print “var=5 and *ptr=XYZ” where XYZ is some random address
     

  • Compile error
     

Question 33

What does the following program print?
 

C
#include
void f(int *p, int *q)
{
  p = q;
 *p = 2;
}
int i = 0, j = 1;
int main()
{
  f(&i, &j);
  printf(\"%d %d \\n\", i, j);
  getchar();
  return 0;
}
  • 2 2
     

  • 2 1
     

  • 0 1
     

  • 0 2 
     

Question 34

What does the following expression means ? 
char ∗(∗(∗ a[N]) ( )) ( );
 

  • a pointer to a function returning array of n pointers to function returning character pointers.
     

  • a function return array of N pointers to functions returning pointers to characters
     

  • an array of n pointers to function returning pointers to characters
     

  • an array of n pointers to function returning pointers to functions returning pointers to characters.
     

Question 35

The following statement in ‘C’ 
int (*f())[ ]; 
declares
 

  • a function returning a pointer to an array of integers.
     

  • a function returning an array of pointers to integers.
     

  • array of functions returning pointers to integers.
     

  • an illegal statement.
     

Question 36

Assume that a character takes 1 byte. Output of following program? 
 

C
#include<stdio.h>
int main()
{
    char str[20] = \"GeeksQuiz\";
    printf (\"%d\", sizeof(str));
    return 0;
}
  • 9
     

  • 10
     

  • 20
     

  • Garbage Value
     

Question 37

Predict the output of following program, assume that a character takes 1 byte and pointer takes 4 bytes.
 

C
#include <stdio.h>
int main()
{
    char *str1 = \"GeeksQuiz\";
    char str2[] = \"GeeksQuiz\";

    printf(\"sizeof(str1) = %d, sizeof(str2) = %d\",
           sizeof(str1), sizeof(str2));

    return 0;
}
  • sizeof(str1) = 10, sizeof(str2) = 10 

     

  • sizeof(str1) = 4, sizeof(str2) = 10
     

  • sizeof(str1) = 4, sizeof(str2) = 4
     

  • sizeof(str1) = 10, sizeof(str2) = 4
     

Question 38

A language with string manipulation facilities uses the following operations. 

head(s)- returns the first character of the string s 
tail(s)- returns all but the first character of the string s 
concat(sl, s2)- concatenates string s1 with s2. 

The output of concat(head(s), head(tail(tail(s)))), where s is acbc is
 

  • ab
     

  • ba
     

  • ac
     

  • as
     

Question 39

In below program, what would you put in place of “?” to print “Quiz”?
 

C
#include <stdio.h>
int main() 
{ 
  char arr[] = \"GeeksQuiz\"; 
  printf(\"%s\", ?); 
  return 0; 
}
  • arr
     

  • (arr+5)
     

  • (arr+4)
     

  • Not possible
     

Question 40

Consider the following C program segment. 
 

C
# include <stdio.h>
int main( )
{
    char s1[7] = \"1234\", *p;
    p = s1 + 2;
    *p = \'0\' ;
    printf (\"%s\", s1);
}

What will be printed by the program?
 

  • 12 

     

  • 120400
     

  • 1204 
     

  • 1034
     

There are 50 questions to complete.

Last Updated :
Take a part in the ongoing discussion