These C Programming multiple-choice questions and their answers will help you strengthen your grip on the subject of C Programming. You can prepare for an upcoming exam or job interview with these C Programming MCQs.
So scroll down and start answering.
A. main()
B. program()
C. start()
A. Format string
B. Stack overflow
C. Integer overflow
D. Race condition
E. Heap overflow
A. switch
B. static
C. extern
D. intern
E. struct
A. True
B. False
A. True
B. False
A. for(;;) { }
B. while(1) { }
C. loop: ... goto loop;
D. All answers are right.
A. It will include dir/x.h if __APPLE__ is defined, or other_dir/x.h, otherwise.
B. It will define __APPLE__, include dir/x.h and next time will include other_dir/x.h
C. It will define __APPLE__ and include dir/x.h
D. It will include dir/x.h if __APPLE__ is not defined, or other_dir/x.h, otherwise.
A. 0
B. 1
C. 5
D. 4
A. Program will not execute.
B. Array not initialized correctly
C. 6
D. Compile time error
A. 0.5
B. 0
C. Undefined
A. It will crash your program (an int is four bytes long, not two).
B. Nothing, it will yield a type mismatch compiler error.
C. It will make p point to an uninitialized two-byte piece of memory allocated from the heap.
D. It will make p point to the number 2.
A. a[0]th value of array
B. a[last]th value of array
C. All elements of an array
D. Address of array
A. tabulations
B. tags
C. angle brackets
D. curly braces
E. indentation
A. 0
B. 2
C. 1
A. None of them
B. Logical operator
C. Arithmetic Operator
D. Relational Operator
A. 5
B. 6
C. 6.0
D. 5.60
E. 5.666666
A. No
B. Yes
A. - (hyphen)
B. * (asterisk)
C. _ (underscore)
D. | (pipeline)
A. An int *
B. An int
C. It does not compile
A. =
B. equal
C. ==
D. :=
A. char
B. float
C. var
D. double
E. int
A. float
B. real
C. int
A. .
B. +
C. :
D. ;
A. False
B. True
A. 6
B. 3
C. 9
D. It depends on the compiler and the hardware architecture.
E. 12
A. value of variable b
B. address of variable a
C. value of variable a
D. address of variable b
A. It will cause segfault
B. no
C. yes
D. It will not compile
A. its size depends on the implementation
B. its size is 128 bits
C. it's an alias of float
D. it uses the GPU
A. arr[0]
B. (both of these)
C. *arr
A. float, double, long double
B. double, long int, float
C. short int, double, long int
D. float, double
A. 6
B. 14
C. 18
D. 10
A. *(&foo + 4)
B. (*foo + 4)
C. There is no equivalent using those notations
D. &(foo + 4)
E. *(foo + 4)
A. Undefined
B. 2
C. 1
A. Nothing, it will give a runtime error.
B. Nothing, it won't compile.
C. Unknown, it depends on what malloc will return.
D. 0
A. 2
B. 0
C. 1
D. 3
A. actual arguments
B. formal arguments
C. array definitions
D. arguments with data types
E. macros used with variable argument functions
A. double
B. long
C. float
D. int
A. doThis(*array)
B. doThis(array[size])
C. doThis(&array)
D. doThis(array)
A. 2
B. Depends on the implementation, but always some number > 1.
C. 1
D. 4
E. Depends on the implementation, but always some number >= 1.
A. True
B. False
A. ~
B. ^
C. <<
D. !
E. |
A. ELANCE
B. NULL
C. Sengmentation Fault
D. It Won't Compile
A. NULL
B. The program segfault
C. The behavior is implementation-defined
D. A unique pointer
A. *p
B. &p
C. &(p)
D. **(p)
E. *(*p)
A. Garbage
B. Null
C. Not equal
D. Equal
E. Compilation error
A. 24
B. 2
C. 4
D. 1
E. 3
A. 0 0
B. 1 1
C. 1 3
D. Garbage Values of i & j
E. Compile Time Error
A. False
B. True
A. 0
B. 1
C. 25
D. -1
E. 2
A. fopen
B. close
C. printf
A. Compiler error
B. Sachin
C. Rahul
D. null
E. Runtime error
A. a=22 b=34
B. a=22 b=24
C. a=28 b=34
D. a=28 b=24
A. Strings are surrounded with double quotes, and Character with single-quotes.
B. Strings and chars can be surrounded with double quotes or single-quotes.
C. Strings does not exists in C.
A. 63
B. 14
C. 12
D. 31
Which of the following is the correct way of initializing a two-dimensional array?
A. char str[2][4]={ "abc", "def" };
B. char str[2][4]={ {"abc"}, {"def"} };
C. char str[2][4]={ {'a','b','c','\0'}, {'d','e','f','\0'} };
D. a and b
E. a, b and c
Which of the following statements are correct for the keyword register?
A. It is a storage-class-specifier
B. It guarantees that the variable is kept in the CPU register for maximum speed
C. It requests that the variable be kept in the CPU register for maximum speed
D. It does not guarantee that the variable value is kept in CPU register for maximum speed
What would be printed on the standard output as a result of the
following code snippet?
main( )
{
char *str[ ] = {
"Manish"
"Kumar"
"Choudhary"
};
printf ( "\nstring1 = %s", str[0] );
printf ( "\nstring2 = %s", str[1] );
printf ( "\nstring3 = %s", str[2] );
}
A. string1 = Manish string2 = Kumar string3 = Choudhary
B. string1 = Manish string2 = Manish string3 = Manish
C. string1 = ManishKumarChoudhary string2 = (null) string3 = (null)
D. You will get an error message from the compiler
What would be printed on the standard output as a result of the
following code snippet?
int Recur(int num)
{
if(num==1 || num==0)
return 1;
if(num%2==0)
return Recur(num/2)+2;
else
return Recur(num-1)+3;
}
int main()
{
int a=9;
printf("%d\n", Recur(a));
return 0;
}
A. 10
B. 9
C. 11
D. 8
E. None of the above
Read the following two declaration statements.
1. #include
2. #include "stdio.h"
Which of the following statements pertaining to the above two
statements are correct?
A. For statement 1, the header file will be searched first in the local directory and then in the standard system directories such as "/usr/include"
B. For statement 1, the header file will be searched in the standard system directories such as "/usr/include"
C. For statement 2, the header file will be searched first in the local directory and then in the standard system directories such as "/usr/include"
D. For statement 2, the header file will be searched in the standard system directories such as "/usr/include"
E. None of the above
Study the following code where num is an integer array and n is the
length of the array:
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(num[i] > num[j])
{
var=num[i];
num[i]=num[j];
num[j]=var;
}
}
}
What does the above code do?
A. It prints the elements of the array in the ascending order
B. It calculates the sum of the elements of the array
C. It sorts the array in the ascending order
D. It sorts the array in the descending order
E. It calculates the average of the elements of the array
Given the following array declaration:
int a[2][3][4]
what would be the number of elements in array a?
A. 24
B. 22
C. 20
D. 12
E. 36
Which of the following file modes would mean read + append?
A. w+
B. a+
C. r+
D. r+a
E. a+r
Which header file are methods(or macros) isalpha(), islower() a part
of?
A. stdio.h
B. ctype.h
C. string.h
D. math.h
E. None of the above
Suppose there is a file a.dat which has to be opened in the read
mode using the FILE pointer ptr1, what will be the correct syntax?
A. ptr1 = open("a.dat");
B. ptr1 = fileopen("a.dat");
C. ptr1 = fopen("a.dat","r");
D. ptr1 = open("a.dat","r");
E. ptr1 = fileopen("a.dat","r");
Which of the following is not a storage type?
A. auto
B. global
C. static
D. register
E. extern
Which of the following sets of conversion statements may result in the
loss of data?
A. int i; char c; i=c; c=i;
B. int i; char c; c=i; i=c;
C. int i; float f; i=f; f=i;
D. None of the above
Which function allocates memory and initializes elements to 0?
A. assign()
B. calloc()
C. malloc()
D. swab()
E. allocate()
Which function will you use to position the file pointer at the beginning
of the file?
A. rewind()
B. fseek()
C. fscanf()
D. a or b
E. b or c
Which function will convert a string into an integer?
A. int()
B. number()
C. atoi()
D. val()
E. tonum()
What will be printed on the standard output as a result of the following
code snippet?
void main()
{
int i,j,k;
i=4;
j=30;
k=0;
k=j++/i++;
++k;
printf("%d %d %d",i,j,k);
}
A. 5 31 8
B. 5 31 7
C. 5 31 6
D. 4 30 7
What does the argv[0] represent?
A. The first command line parameter has been passed to the program
B. The program name
C. The number of command line arguments
D. None of the above
Which of the following is a function for formatting data in memory?
A. sprintf()
B. printf()
C. scanf()
D. free()
E. atol()
What would be printed on the standard output as a result of the
following code snippet?
main()
{
int n=5, x;
x = n++;
printf("%d ", x);
x = ++n;
printf("%d ", x++);
printf("%d", x);
return 0;
}
A. 6 7 8
B. 5 7 8
C. 6 8 8
D. 5 8 8
E. None of the above
What will be the output of the following program, assuming that data
type short takes 2 bytes for storage?
struct node
{
unsigned char bit1 : 1;
unsigned char bit2 : 1;
unsigned short bit3 : 7;
} node1;
main()
{
int size = sizeof(node1);
printf("%d", size);
}
A. 4
B. 3
C. 2
D. None of the above
What would be printed on the standard output as a result of the
following code snippet?
main()
{
enum {red, green, blue = 6, white};
printf("%d %d %d %d", red, green, blue, white);
return 0;
}
A. 0 1 6 2
B. 0 1 6 7
C. Will result in Compilation Error
D. None of the above
Read the statement below:
extern int a;
Which of the following statement/s pertaining to the above statement
is/are correct?
A. Declares an integer variable a; Allocates storage for the variable
B. Declares an integer variable a; Does not allocate the storage for the variable
C. Indicates that the variable is defined outside the current file
D. Brings the scope of the variable defined outside the file to this file
E. All of the above
F. None of the above
What is the return type of the following function declaration?
func(char c);
A. void
B. char
C. int
D. undefined
The declaration int *(*p)[10] indicates:
A. p is an array of pointers to functions the return type of which is an integer
B. p is a pointer to a function that returns a pointer to an integer
C. p is a pointer to an array of integer pointers
D. p is a pointer to a character string
What would be printed on the standard output as a result of the
following code snippet?
main()
{
void addup (int b);
addup(b);
return 0;
}
int b = 5;
void addup (int b)
{
static int v1;
v1 = v1+b;
printf("%d ", v1);
}
A. Will result in Compilation Error
B. 5
C. 0
D. Undefined value
What would be printed on the standard output as a result of the
following code snippet?
main()
{
char *pmessage = "asdfgh";
*pmessage++;
printf("%s", pmessage);
return 0;
}
A. Will result in Compilation Error
B. Undefined string
C. sdfgh
D. asdfgh
Select the correct statement about arrays.
A. Automatic arrays cannot be initialized
B. An array declared as A[100][100] can hold a maximum of 10000 elements
C. An array can hold elements of different data types
What will be printed on the standard output as a result of the following
code snippet?
void main()
{
char arr[] = {'R','A','M','\0'};
printf("%d",strlen(arr));
}
A. 0
B. 1
C. 3
D. 4
E. Cannot be determined
What happens when the continue keyword is encountered in the 'for
loop'?
A. Control passes to the initialization of the loop
B. Control passes to the condition of the loop
C. Control passes to the beginning of the loop
D. Control passes to the first statement of the loop
E. Control passes to the statement preceding the end of the loop
Given the following array:
char books[][40]={
"The Little World of Don Camillo",
"To Kill a Mockingbird",
"My Family and Other Animals",
"Birds, Beasts and Relatives"
};
what would be the output of printf("%s",books[3]);?
A. Birds
B. B
C. Birds, Beasts and Relatives
D. My Family and Other Animals
E. M
What will happen when the following code is executed?
void main()
{
char arr1[] = "REGALINT";
char *arr2;
arr2 = arr1;
printf("%d,",sizeof(arr1));
printf("%d",sizeof(arr2));
}
A. 1,1
B. 1,4
C. 8,8
D. 8,9
E. 9,4
What will be printed on the standard output as a result of the following
code snippet?
void main()
{
char arr1[] = "REGALINT";
printf("%d,",strlen(arr1));
printf("%d",sizeof(arr1));
}
A. 1,1
B. 8,4
C. 8,8
D. 8,9
E. 9,8
Which function will convert a string into a double precision quantity?
A. atoi()
B. atof()
C. atol()
D. atan()
E. acos()
By which file function you can position the file pointer in accordance
with the current position?
A. ftell()
B. fseek()
C. fgetc()
D. fread()
E. fscanf()
What would be printed on the standard output as a result of the
following code snippet?
#define Name Manish
main()
{
printf("My name""Name");
}
A. My name Manish
B. My nameName
C. Results in Compilation Error
D. None of the above
Which of the following is/are the correct signature/s of main with
command line arguments?
A. int main(int argc, char **argv)
B. int main(int argc, char *argv[])
C. int main(int argc, char *argv)
D. int main(int argc, char argv[])
E. All of the above
Which of the following statements will result in a compilation error?
A. int n=5, x; x=n++;
B. int n=5, x; x= ++n++;
C. int n=5, x; x= (n+1)++;
D. int n=5, x=6; x= (n+x)++;
E. None of the above
Which is/are the type/s of memory allocation that needs/need the
programmer to take care of memory management?
A. Static memory allocation
B. Dynamic memory allocation
C. Automatic memory allocation
D. Memory allocation on stack
E. Memory allocation on heap
What is the function to concatenate two strings?
A. strcmp()
B. strcpy()
C. strcat()
D. strlen()
E. catstr()
What would be printed on the standard output as a result of the
following code snippet?
#define max(a, b) ((a) > (b)?(a):(b))
main()
{
int a=4;
float b=4.5;
printf("%.2f\n",max(a, b));
}
A. Results in Compilation Error
B. Undefined value
C. 4.50
D. 4.0
E. None of the above
Given the operators:
1) *
2) /
3) %
What would be the order of precedence?
A. 1,2,3
B. 1,3,2
C. 3,2,1
D. All have the same precedence
E. 1 and 2 have the same precedence, 3 is of lower precedence
What will happen if you assign a value to an element of an array the
subscript of which exceeds the size of the array?
A. The element will be set to 0
B. Nothing; it is commonly done
C. It is undefined behavior
D. You will get an error message from the compiler
What would be printed on the standard output as a result of the
following code snippet?
void main()
{
unsigned char a=25;
a = ~a;
signed char b = 25;
b = ~b;
printf("%d %d ", a, b);
}
A. 0 0
B. 230 230
C. 230 -26
D. 230 -103
E. None of the above
A. fgetc()
B. puts()
C. fputc()
D. fscanf()
E. fprintf()
Which function will you use to write a formatted output to the file?
A. fputc()
B. fputs()
C. fprintf()
D. fseek()
E. ftell()
Given the array:
int num[3][4]= {
{3,6,9,12},
{15,25,30,35},
{66,77,88,99}
};
what would be the output of *(*(num+1)+1)+1?
A. 3
B. 15
C. 26
D. 66
E. 77