Top 50 C PROGRAMMING MCQ Questions and Answers Exercise (Set 3/4)

By Sahil Bansal | Views: 3265

Q 1 - Linker generates ______ file.

A - Object code
B - Executable code
C - Assembly code
D - None of the above.

Q 2 - Compiler generates ______ file.

A - Executable code
B - Object code
C - Assembly code
D - None of the above.

Q 3 - Special symbol permitted within the identifier name.

A - $
B - @
C - _
D - .

Q 4 - A single line comment in C language source code can begin with ______.

A - ;
B - :
C - /*
D - //

Q 5 - A macro can execute faster than a function.

A - true
B - false

Q 6 - Choose the invalid identifier from the below

A - Int
B - volatile
C - DOUBLE
D - __0__

Q 7 - Choose the application option for the following program?

#include<stdio.h>
main()
{
   int *p, **q;
   printf("%u\n", sizeof(p));
   printf("%u\n", sizeof(q));
}

A - Both the printf() will print the same value
B - First printf() prints the value less than the second.
C - Second printf() prints the value less than the first.
D - Error in the code.

Q 8 - What is the built-in library function to adjust the allocated dynamic memory size.

A - malloc
B - calloc
C - realloc
D - resize

Q 9 - Identify the C compiler of UNIX.

A - gcc
B - cc
C - Borland
D - vc++

Q 10 - Following is the invalid inclusion of a file to the current program. Identify it.

A - #include <file>
B - #include “file”
C - #include < file
D - All of the above is invalid.

Q 11 - What is the output of the following program?

#include<stdio.h>
int* f() 
{
   int x = 5;
   return &x;
}
main() 
{
   printf("%d", *f());
}

A - 5
B - Address of ‘x’
C - Compile error
D - Runtime error

Q 12 - What is the output of the following program?

#include<stdio.h>
main() 
{
   char *p = NULL;
   printf("%c", *p);
}

A - NULL
B - 0
C - Compile error
D - Runtime error.

Q 13 - The default executable generation on UNIX for a C program is ______.

A - a.exe
B - a
C - a.out
D - out.a

Q 14 - What is the output of the following program?

#include<stdio.h>
void f() 
{
   static int i = 3;
   printf("%d ", i);
   if(--i) f();
}
main() 
{
   f();
}

A - 3 2 1 0
B - 3 2 1
C - 3 3 3
D - Compile error

Q 15 - What is the output of the following program?

#include<stdio.h>
main() 
{
}

A - No output
B - Garbage
C - Compile error
D - Runtime error

Q 16 - Choose the correct option with respect to the following program.

#include<stdio.h>
void f(int const i) 
{
   i=5;
}
main() 
{
   int x = 10;
   f(x);
}

I - Error in the statement ‘void f(int const i)’
II - Error in the statement i=5.

A - Statements I & II are true
B - Statements I & II are false.
C - Statement I is true
D - Statement II is true.

Q 17 - To store a word/sentence declare a variable of the type ‘string’.

A - true
B - false

Q 18 - What is the output of the following program?

#include<stdio.h>
int x = 5;
int* f() 
{
   return &x;
}
main()
{
   *f() = 10;
   printf("%d", x);
}

A - Compile error
B - Runtime error
C - 5
D - 10

Q 19 - What is the output of the below code snippet.

#include<stdio.h>
main()
{
   printf("%d", -11%2);
}

A - 1
B - -1
C - 5.5
D - -5.5

Q 20 - An exception is ______.

A - Runtime error
B - Compile-time error
C - Logical error
D - None of the above

Q 21 - Do both the loops in the following programs print the correct string length?

#include<stdio.h>
main()
{
   int i;
   char s[] = "hello";
   for(i=0; s[i]; ++i);
      printf("%d ", i);
   i=0; 
   while(s[i++]);
      printf("%d ", i);
}

A - Yes, both the loops prints the correct length
B - Only for loop prints the correct length
C - Only while loop prints the correct length
D - Compile error in the program.

Q 22 - For the below definition what is the data type of ‘PI’

#define PI 3.141

A - It's float
B - It's double
C - There is no type associated with PI, as it’s just a text substitution
D - Syntax error, the semicolon is missing with the definition of PI

Q 23 - Choose the invalid predefined macro as per ANSI C.

A - __FILE__
B - __DATE__
C - __TIME__
D - __C++__

Q 24 - What is the output of the following program?

#include<stdio.h>
main()
{
   int a[] = {10, 20, 30};
   printf("%d", *a+1);
}

A - 10
B - 20
C - 11
D - 21

--------------------------------------------------------------------------------------------------------------------------------------------

Practice more questions

-------------------------------------------------------------------------------------------------------------------------------------------

Q 25 - What is the output of the following program?

#include<stdio.h>
void f(int a[])
{  
   int i;
   for(i=0; i<3; i++)
      a[i]++;
}
main()
{
   int i,a[] = {10, 20, 30};
   f(a);
   for(i=0; i<3; ++i)
   {
      printf("%d ",a[i]);
   }
}

A - 10 20 30
B - 11 21 31
C - Compile error
D - Runtime error

Q 26 - What is the output of the following program?

#include<stdio.h>
main()
{
   char *s = "Hello, "
   "World!";
   printf("%s", s);
}

A - Hello, World!
B - Hello,World!
C - Hello
D - Compile error

Q 27 - What is the output of the following program?

#include<stdio.h>
main()
{
   fprintf(stdout,"Hello, World!");
}

A - Hello, World!
B - No output
C - Compile error
D - Runtime error

Q 28 - What is the output of the following program?

#include<stdio.h>
main()
{
   fprintf(stdout,"Hello, World!");
}

A - Hello, World!
B - No output
C - Compile error
D - Runtime error

Q 29 - Which of the following is used in the mode string to open the file in binary mode?

A - a
B - b
C - B
D - bin

Q 30 - What is the output of the following program?

#include<stdio.h>
main()
{
   char s[] = "Fine";
   *s = 'N';
   printf("%s", s);
}

A - Fine
B - Nine
C - Compile error
D - Runtime error

Q 31 - What is the output of the following program?

#include<stdio.h>
main()
{
   char *s = "Fine";
   *s = 'N';
   printf("%s", s);
}

A - Fine
B - Nine
C - Compile error
D - Runtime error

Q 32 - What is the output of the following program?

#include<stdio.h>
main()

   int x;
   float y;
   y = x = 7.5;
   printf("x=%d y=%f", x, y);
}

A - 7 7.000000
B - 7 7.500000
C - 5 7.500000
D - 5 5.000000

Q 33 - What is the built-in library function to compare two strings?

A - string_cmp()
B - strcmp()
C - equals()
D - str_compare()

Q 34 - What is the output of the following program?

#include<stdio.h>
main()

   char s1[50], s2[50] = "Hello";
   s1 = s2;
   printf("%s", s1);
}

A - Hello
B - No output
C - Compile error
D - Runtime error

Q 35 - What is the output of the following program?

#include<stdio.h>
int main();
void main()
{
   printf("Okay"); 
}

A - Okay
B - No output
C - Compile error. We cannot declare main() function.
D - Compile error. Mismatch in declaration & definition.

Q 36 - What is the output of the following program?

#include<stdio.h>
void main()
{
   char *s = "C++";
   printf("%s ", s);
   s++;
   printf("%s", s);
}

A - C++ C++
B - C++ ++
C - ++ ++
D - Compile error

Q 37 - What is the output of the following program?

#include<stdio.h>
void main()
{
   char s[] = "C++";
   printf("%s ",s);
   s++;
   printf("%s",s);
}

A - C++ C++
B - C++ ++
C - ++ ++
D - Compile error

Q 38 - A local variable is stored in ______.

A - Code segment
B - Stack segment
C - Heap segment
D - None of the above

Q 39 - What is the output of the following statement?

#include<stdio.h>
main()
{
   printf("%d", -1<<1 );  
}

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

Q 40 - What is the output of the following program?

#include<stdio.h>
main()

   int x = 3;
   x += 2;
   x =+ 2;
   printf("%d", x); 
}

A - 2
B - 5
C - 7
D - Compile error

Q 41 - What is the output of the following program?

#include<stdio.h>
main()

   char *s = "Abc";
   while(*s)
      printf("%c", *s++);
}

A - Abc
B - bc
C - Compile error
D - Runtime error

Q 42 - What is the output of the following program?

#include<stdio.h>
main()

   char s[20] = "Hello\0Hi";
   printf("%d %d", strlen(s), sizeof(s));
}

A - 5 9
B - 7 20
C - 5 20
D - 8 20

Q 43 - What is the output of the following program?

#include<stdio.h>
main()

   char s[] = "Hello\0Hi";
   printf("%d %d", strlen(s), sizeof(s));
}

A - 5 9
B - 7 20
C - 5 20
D - 8 20

Q 44 - What is the output of the following statement?

#include<stdio.h>
main()

   printf("%d", !0<2);
}

A - 0
B - 1
C - False
D - True

Q 45 - What is the output of the following program?

#include<stdio.h>
main()

   struct student
   { 
       int num = 10;
   }var;
   printf("%d", var.num);
}

A - 10
B - Garbage
C - Runtime error
D - Compile error

Q 46 - What is the output of the following program?

#include<stdio.h>
#define sqr(i) i*i
main()
{
   printf("%d %d", sqr(3), sqr(3+1)); 
}

A - 9 16
B - 9 7
C - Error: macro cannot be defined in lower case.
D - None of the above.

Q 47 - What is the output of the following program?

#include<stdio.h>
main()
{
   char *s = "Hello";
   while(*s!=NULL)
   printf("%c", *s++);
}

A - Hello
B - Helloellolloloo
C - ello
D - Compile error

Q 48 - What is the output of the following program?

#include<stdio.h>
main()
{  
   #undef NULL
   char *s = "Hello";
   while(*s != NULL)
   {
      printf("%c", *s++);
   }
}

A - Hello
B - Compile error: there is no macro called “undef”
C - Compile error: an improper place of #undef
D - Compile error: NULL is undeclared.

Q 49 - C is the successor of ______ programming language.

A - C++
B - B++
C - B
D - Mini C

Q 50 - Which of the following functions disconnects the stream from the file pointer.

A - fremove()
B - fclose()
C - remove()
D - file pointer to be set to NULL

--------------------------------------------------------------------------------------------------------------------------------------------

 QUESTION NO. ANSWERS
1.B
2.B
3.C
4.D
5.A
6.B
7.A
8.C
9.B
10.C
11.D
12.D
13.C
14.B
15.A
16.D
17.B
18.D
19.B
20.A
21.B
22.C
23.D
24.C
25.B
26.A
27.C
28.A
29.B
30.B
31.D
32.A
33.B
34.C
35.D
36.B
37.D
38.B
39.B
40.A
41.A
42.C
43.A
44.B
45.D
46.B
47.A
48.D
49.C
50.B

--------------------------------------------------------------------------------------------------------------------------------------------

ALSO READ:

Top 50 C PROGRAMMING MCQ Questions and Answers with Explanation

Top 50 C PROGRAMMING MCQ Questions and Answers Exercise (Set 1/4)

Top 50 C PROGRAMMING MCQ Questions and Answers Exercise (Set 2/4)

Top 50 C PROGRAMMING MCQ Questions and Answers Exercise (Set 4/4)

Practice our complete set of quantitative and English

-------------------------------------------------------------------------------------------------------------------------------------------

Thank you for your feedback!