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

By HH Team | Views: 277
       

Q 1 - What actually gets a pass when you pass an array as a function argument?

A - First value of elements in the array
B - Base address of the array
C - All value of the element in the array
D - Address of the last element of the array

Q 2 - In the given below code, the function fopen()uses "r" to open the file “source.txt” in binary mode for which purpose?

#include<stdio.h>
int main ()
{
   FILE *fp;

   fp = fopen("source.txt", "r");
   return 0;
}

A - For reading
B - For reading and writing
C - For creating a new file "source.txt" for reading
D - For creating a new file "source.txt" for writing

Q 3 - In DOS, how many bytes exist for near, far, and huge pointers?

A - Near: 2, far: 4, huge: 7
B - near: 4, far: 2, huge: 8
C - near: 2, far: 4, huge: 4
D - near: 4, far: 0, huge: 0

Q 4 - fgets() function is safer than gets() because in fgets() function you can specify the size of the buffer into which the supplied string will be stored.

A - True
D - False

Q 5 - Which scanf() statement will you use to scan a float value (a) and double value (b)?
   Float a;
   Double b;

A - scanf("%f %f", &a, &b);
B - scanf("%lf % lf ", &a, &b);
C - scanf("%Lf %Lf", &a, &b);
D - scanf("%f %lf", &a, &b);

Q 6 - Choose the correct statement that is a combination of these two statements,
   Statement 1: char *p;
   Statement 2: p = (char*) malloc(100);

A - char p = *malloc(100);
B - char *p = (char*)malloc(100);
C - char *p = (char) malloc(100);
D - None of the above

Q 7 - Which of the following header file can be used to define the NULL macro?

A - stdio.h, locale.h, stddef.h, stdlib.h, string.h,
B - stddef.h, locale.h, math.h, stdlib.h, string.h,
C - time.h, wchar.h, math.h, locale.h,
D - math.h

Q 8 - In the given below code, the P2 is
   Typedef int *ptr;
   ptr p1, p2;

A - Integer
B - Integer pointer
C - Both, Integer & Integer pointer
D - None of above

Q 9 - In the following code, what is 'P'?
   Typedef char *charp;
   const charp P;

A - P is a constant
B - P is a character type
C - P is a pointer
D - None of the above

Q 10 - What is x in the following program?
#include<stdio.h>
int main ()
{
   typedef char (*(*arrfptr[3])())[10];
   arrfptr x
   return 0;
}

A - x is a character pointer
B - x is an array of pointer
C - x is an array of three function pointers
D - Wrong declaration

Q 11 - What will be the resultant of the given below program?
#include<stdio.h>
#include<stdarg.h>
Void fun(char *msg, ...);
int main ()
{
   fun("IndiaMAX", 1, 4, 7, 11, 0);
   return 0;
}
   void fun(char *msg, ...)  
{
va_list ptr;{
   int num;
   va_start(ptr, msg);
   num = va_arg(ptr, int);    
   num = va_arg(ptr, int);
   printf("%d", num);
}

A - IndiaMAX 1, 7, 11, 0
B - IndiaMAX 1, 7
C - Only 4
D - 1, 7, 11, 0

Q 12 - The correct order of evaluation for the expression “z = x + y * z / 4 % 2 – 1”

A - * / % = + -
B - / * % - + =
C - - + = * % /
D - * / % + - =

Q 13 - In C, what is the correct hierarchy of arithmetic operations?

A - */ + -
B - * +- /
C - / *+ -
D - + - / *

Q 14 - To print a double value which format specifier can be used?

A - %L
B - %lf
C - %Lf
D - None of the above

Q 15 - Which files will get closed through the fclose() in the following program?

#include<stdio.h>
int main ()
{
   FILE *fs, *ft, *fp;
   fp = fopen("ABC", "r");
   fs = fopen("ACD", "r");
   ft = fopen("ADF", "r");
   fclose(fp, fs, ft);
return 0;
}

A - "ABC"
B - "ACD"
C - "ADF"
D - Return error

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

Practice more questions

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

Q 16 - Which of the following statement shows the correct implementation of nested conditional operation by finding the greatest number out of three numbers?

A - max = a>b ? a>c?a:c:b>c?b:c
B - a=b ? c=30;
C - a>b : c=30 : c=40;
D - return (a>b)?(a:b) ?a:c:b

Q 17 - Choose the correct order from given below options for the calling function of the code “a = f1(23, 14) * f2(12/4) + f3();”?

A - f1, f2, f3
B - f3, f2, f1
C - f2, f1, f3
D - Order may vary from one compiler to another

Q 18 - What will be the output of the following program?
#include<stdio.h>
int main()
{
   const int i = 0;
   printf("%d\n", i++);
   return 0;
}

A - 100
B - Infinity
C - 0
D - Return error

Q 19 - An operation with only one operand is called a unary operation.

A - Yes
B - An operation with two operands is called a unary operation
C - An operation with unlimited operand is called unary operation
D - None of the above

Q 20 - Choose the correct order of evaluation,

A - Relational Arithmetic Logical Assignment
B - Arithmetic Relational Logical Assignment
C - Logical Arithmetic Relational Assignment
D - Assignment Arithmetic Logical Relational

Q 21 - Which printf() statement will you use to print out a (float value) and b (double value)?
   Float a = 3.14;
   Double b = 3.14;

A - printf("%f %lf", a, b);
B - printf("%f %f", a, b);
C - printf("%Lf %Lf", a, b);
D - printf("%f %Lf", a, b);

Q 22 - To print a float value which format specifier can be used?

A - %f
B - %lf
C - %Lf
D - None of the above

Q 23 - Choose the correct unary operators in C – a) !, b) ~, c) ^&, d) ++

A - a, b, d
B - a, b, c
C - b, c, d
D - c, d, a

Q 24 - What will be the output of the following program?
#include<stdio.h>
int main()
{
   const int x = 5;
   const int *ptrx;
   ptrx = &x;
   *ptrx = 10;
   printf("%d\n", x);
   return 0;
}

A - 10
B - 20
C - 0
D - The program will return an error

Q 25 - What do the following statement define?
   int *ptr[10];

A - ptr is a pointer to an array of 10 integer pointers.
B - ptr is an array of 10 pointers to integers
C - ptr is an array of 10 integer pointers
D - None of the above

Q 26 - What is the role of "r+" on the file "NOTES.TXT" in the given below code?
#include<stdio.h>
int main ()
{
   FILE *fp;
   fp = fopen("NOTES.TXT", "r+");
   return 0;
}

A - "r+" open the file "NOTES.TXT" file for reading
B - "r+" open the file "NOTES.TXT" file for writing
C - "r+" open the file "NOTES.TXT" file for appending
D - "r+" open the file "NOTES.TXT" file for reading & writing both

Q 27 - In the given below code, what will be return by the function get ()?
#include<stdio.h>
int get();
int main()
{
   const int x = get();
   printf("%d", x);
   return 0;
}
   int get()
   {
    return 40;
}

A - 40
B - 20
C - 0
D - Error

Q 28 - During preprocessing, the code “#include<stdio.h>” gets replaced by the contents of the file stdio.h.

A - Yes
B - During linking the code “#include<stdio.h>” replaces by stdio.h
C - During execution the code “#include<stdio.h>” replaces by stdio.h
D - During editing the code “#include<stdio.h>” replaces by stdio.h

Q 29 - What value strcmp() function returns when two strings are the same?

A - 0
B - 2
C - 1
D - Error

Q 30 - What will be the output of the given below program in TurboC

#include<stdio.h>
int fun(int **ptr);
int main()
{
    int i = 10, j = 20;
    const int *ptr = &i;
    printf(" i = %5X", ptr);
    printf(" ptr = %d", *ptr);
    ptr = &j;
    printf(" j = %5X", ptr);
    printf(" ptr = %d", *ptr);
    return 0;
}

A - i= FFE6 ptr=30 j=FFE4 ptr=36
B - i= FFE0 ptr=04 j=FFE1 ptr=30
C - i= FFE4 ptr=10 j=FFE2 ptr=20
D - None of the above

Q 31 - What will be the output of the given below code?
#include<stdio.h>
int main()
{
   const int *ptr = &i;
   char str[] = "Welcome";
   s = str;
   while(*s)
   printf("%c", *s++);
   return 0;
}

A - Welcome
B - 0
C - Wel
D - Come

Q 32 - Which statement can print \n on the screen?

A - printf("\\n");
B - printf("n\");
C - printf("n");
D - printf('\n');

Q 33 - According to ANSI specification, how to declare the main () function with command-line arguments?

A - int main(int argc, char *argv[])
B - int char main(int argc, *argv)
C -
int main()
{
   Int char (*argv argc);
)
D - None of the above

Q 34 - In the given below code, what will be the value of a variable x?

#include<stdio.h>
int main()
{
    int y = 100;
    const int x = y;

    printf("%d\n", x);
    return 0;
}

A - 100
B - 0
C - Print x
D - Return Error

Q 35 - The library function strrchr() finds the first occurrence of a substring in another string.

A - Yes
B - Strstr()
C - strchr()
D - strnset()

Q 36 - If, the given below code finds the length of the string then what will be the length?

#include<stdio.h>
int xstrlen(char *s)
{
   int length = 0;
   while(*s!='\0')
   {length++; s++;}
   return (length);
}
   int main()
{
   char d[] = "IndiaMAX";
   printf("Length = %d\n", xstrlen(d));
   return 0;
}

A - Code returns an error
B - Code returns the length 8
C - Code returns the length 6
D - Code returns the length 2

Q 37 - The maximum combined length of the command-line arguments as well as the spaces between adjacent arguments is – a) 120 characters, b) 56 characters, c) Vary from one OS to another

A - a
B - a, b
C - a, b, c
D - c

Q 38 - Choose the function that is most appropriate for reading in a multi-word string?

A - strnset()
B - scanf()
C - strchr()
D - gets()

Q 39 - In the given below statement, what does the “arr” indicate?
   char *arr[30];

A - arr is an array of function
B - arr is an array of 30 characters
C - arr is a pointer to an array
D - arr is an array of 30 character pointers

Q 40 - In the given below statement, what does the “pf” indicate?
   int (*pf)();

A - pf is a pointer of a function that returns an int
B - pf is a pointer
C - pf is a function pointer
D - None of the above

Q 41 - extern int fun(); - The declaration indicates the presence of a global function defined outside the current module or in another file.

A - True
B - False

Q 42 - What is the output of the following program?
#include<stdio.h>
main ()
{
   int i, j;
   for(i=5, j=1; i>j; i--, ++j) 
}

A - 5 2, 4 2
B - Compile error
C - 4 2
D - 5 1, 4 2

Q 43 - What is the output of the following program?
#include<stdio.h>
main ()

   int a=1, b=2, *p=&a, *q=&b, *r=p;
   p = q; q = r;
   printf("%d %d %d %d\n",a,b,*p,*q);
}

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

Q 44 - What is the output of the following program?
#include<stdio.h>
void g(void) { 
}
main ()

   void (*f)(void);
   f = g;
   f();
}

A - Hello
B - Calling f(); is invalid it should be (*f)();
C - void (*f)(void) is an invalid declaration.
D - Instead of f=g, it should be f=&g.

Q 45 - What is the output of the following program?
#include<stdio.h>
int f(int i) {
}
main ()

   printf("%d",f(f(f(f(f(1))))));
}

A - 6
B - 5
C - 1
D - Compilation error

Q 46 - What is the output of the following program?
#include<stdio.h>
main ()

   static int i = 1;
   if(i--) {
   printf("%d ",i);
   main();
  }
}

A - 0
B - 0 infinite
C - Programs hangs with stack overflow
D - Compile error

Q 47 - What is the output of the following program?
#include<stdio.h>
main ()

   printf();
}

A - Program compiles as printf is designed to receive a variable number of arguments.
B - Program fails compilation
C - printf is not a built-in library function
D - Semicolon needs to be removed while calling printf with no parameters.

Q 48 - Does the following program compiles?
#include “stdio.h”

A - It fails as there is no main() function
B - It fails as the header file is enclosed in double quotes
C - It compiles and executes to produce no displayable output
D - It compiles.

Q 49 - What is the output of the following program?
#include<stdio.h>
main ()

   int *p = NULL;
   #undef NULL 
   if(p==NULL) printf("NULL"); 
   else printf("Nill");
}

A - NULL
B - Nill
C - Compile error
D - Runtime error

Q 50 - What is the output of the following program?
main()
{
  puts(__DATE__);
}

A - Prints date and time.
B - Prints date.
C - Compile error, says __DATE__ in undeclared.
D - Compile error: Need to include ‘stdio.h’ as __DATE__ is defined in it.

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

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

Top 50 C PROGRAMMING MCQ Questions and Answers Exercise (Set 3/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!