MCQ Model Questions
MCQ Model Questions
A) 0
B) 1
C) 6
D) compiler error
A) 5 and 6
B) 7 and 4
C) 4 and 7
D) compile error
a. 5,2,3
b. 4,2,3
c. 4,1,3
d. Error
#include <stdio.h>
int main()
{
int y = 10000;
int y = 34;
printf(“Hello World! %d\n”, y);
return 0;
}
a) Compile time error
b) Hello World! 34
c) Hello World! 1000
d) Hello World! Followed by a junk value
a. 0 times
b. 9 times
c. 10 times
d. Infinite times
a. 54321
b. 5432
c. 543
d. 543210
13) For the following loop, when the value is “4”, jump directly to the next value.
a. Ram
b. Compile error
c. Ram is printed unlimited number of times
d. None of the above
19) What is the difference between call by value and call by reference in C language?
a. Call by value passes the address of the argument to the function, while call by reference
passes a copy of the argument value.
b. Call by value passes a copy of the argument value to the function, while call by
reference passes a reference to the argument variable.
c. Call by value and call by reference are the same thing.
d. Call by value passes a reference to the argument variable, while call by reference
passes a copy of the argument value.
#include <stdio.h>
void funct(int a){
a= a*6;
printf("a in funct is %d,",a);
}
int main(){
int a=6;
funct(a);
printf("a in main function is %d ",a);
return 0;
}
25) The value obtained in the function is given back to main by using ________ keyword.
a. static
b. return
c. new
d. volatile
#include <stdio.h>
void swap(int *a, int *b) {
int t = *a;
*a = *b;
*b = t;
}
void function() {
int a = 3, b = 5;
swap(&a, &b);
printf("%d %d", a, b);
}
int main() {
function();
return 0;
}
a. 35
b. 53
c. 55
d. 33
a. 100
b. 36
c. 45
d. 20
#include <stdio.h>
void function() {
int first = 10, second = 20;
int third = first + second;
{
int third = second - first;
printf("%d ", third);
}
printf("%d", third);
}
int main() {
Function();
return 0;
}
a. 10 20
b. 30 10
c. 10 20
d. Compilation error
#include <stdio.h>
void function() {
int a = 3;
int res = a++ + ++a + a++ + ++a;
printf("%d", res);
}
int main() {
function();
return 0;
}
a. 12
b. 20
c. 21
d. 24
31) What is the difference between ‘void func()’ and ‘void func(void)’ in function declarations in C?
a. ‘void func()’ means the function takes no arguments, while ‘void func(void)’ means the
function takes a void argument.
b. ‘void func()’ is a function prototype, and ‘void func(void)’ is a function definition.
c. Both mean the same thing in C.
d. ‘void func()’ is an error in C syntax.
32) What will be the data type returned for the following C function?
#include <stdio.h>
int func()
{
return (double)(char)5.0;
}
a. char
b. int
c. double
d. multiple type-casting in return is illegal
a. double fuc();
int main() { }
double func() { }
b. double func() { };
int main() { }
c. int main()
{
double func();
}
double func() { //statements}
d. None of the mentioned
a. 555
b. 500
c. 5(garbage)(garbage)
d. (garbage)(garbage)5
#include <stdio.h>
int *p;
int main()
{
int i = 5;
p = &i;
printf("%d, %x, %d",i,p,*p);
return 0;
}
a. 5, 62fe1c, 5
b. 5, 433455, 5
c. 5, 5, 433455
d. 5, 5, 5
a. 11, 22
b. 22, 33
c. 11, 33
d. 22, 44
#include <stdio.h>
int main(){
int A[5]= {1,2,3,4,5};
int *p;
p= A;
printf("%d",*(p+1));
return 0;
}
a. 1
b. 3
c. 2
d. 5
Look at the following table and answer the following questions. Addresses and values are
provided for the respective variables used in the program.
a. 50, 200
b. 50, 100
c. 100, 50
d. 2, 50
#include <stdio.h>
int main(){
int a=2;
int *p;
int *q;
p=&a;
q=&p
printf(“%d, %d”,*p,*q);
return 0;
}
a. 2, 50
b. 50, 2
c. 100, 50
d. 2,100
46) Which of the following header files must necessarily be included to use dynamic memory
allocation functions?
a) stdlib.h
b) stdio.h
c) memory.h
d) dos.h
47) Which of the following codes allocate 100 bytes of memory from the heap if sizeof(int)= 4 bytes
and sizeof(char)=1 byte?
a)ptr==NULL;
b)ptr=NULL;
c)ptr==0;
d)ptr=0;
#include <stdio.h>
#include <stdlib.h>
int main()
{
int *j = (int*)malloc(4 * sizeof(int));
*j = 15;
free(j);
printf("%d", *j);
return 0;
}
a. Nothing prints
b. Compilation error
c. Some garbage value
d. 0
#include<stdio.h>
int main()
{
int *p = (int *)malloc(sizeof(int));
p = NULL;
free(p);
}
a. Dangling Pointer
b. Compiler Error: free can’t be applied on NULL pointer
c. The program may crash as free() is called for NULL pointer
d. Memory Leak
void main(){
int i;
int s = 0;
for(i=range.lower;i<=range.upper;i++){
s = s + i;
printf("%d,",s);
}
}
a. 0,1,3,6
b. Garbage value
c. Error
d. 6
#include <stdio.h>
struct student
{
int no;
int age;
}
void main()
{
struct student s= {15, 20};
printf(“%d, %d”, no, age);
}
a. 20, 15
b. 15, 20
c. Compilation error
d. 20, 20
58) The correct syntax to access the member of the structure in the following program?
#include <stdio.h>
struct temp{
int b;
};
int main(){
struct temp s, *p;
p= &s;
}
a) b->p;
b) b.p;
c) p.b;
d) p->b;
#include <stdio.h>
struct temp
{
int a;
};
void func(struct temp s)
{
s.a = 10;
printf("%d\t", s.a);
}
missing int main()
{
else ans is a struct temp s;
s.a=10;
func(s);
printf("%d\t", s.a);
}
a. 10 10
b. Compilation Error
c. 10 Garbage Value
d. Garbage Value 10
#include <stdio.h>
int main(){
struct tree{
int h;
int w;
};
struct tree tree1={10};
printf("%d ",tree1.w);
printf("%d",tree1.h);
return 0;
}
a. 10 10
b. 00
c. 10 0
d. 0 10
63) Which keyword is used to access members of a nested structure in C?
a. .(dot)
b. ->(arrow)
c. ::(scope)
d. ,(comma)
#include <stdio.h>
void main(){
struct student {
int no;
char name[20];
};
struct student s;
no = 8;
printf("%d", no);
}
a. Garbage value
b. Nothing
c. Compile time error
d. 8
68) Which files will get closed through the fclose() in the following program?
#include<stdio.h>
void main(){
FILE *f1, *f2;
f1 = fopen("a.txt", "r");
f2 = fopen("b.txt", "r");
fclose(f1,f2);
}
a. a and b
b. a
c. b
d. Error occurred
71) A mode which is used to open an existing file for both reading and writing ______
a) "w"
b) "r+"
c) "a+"
d) "w+"
73) What is the C function used to move the current pointer to the beginning of a file?
a. rewind()
b. ftell()
c. fwrite()
d. fpointfirst()
a. It will print the content of the file till it encounters a new line character.
b. Compilation Error
c. None of the above
d. It will print the content of file demo.txt
75) What is the output of the following program?
#include <stdio.h>
int main(){
char c;
FILE *fp;
fp=fopen("demo.txt","w");
fprintf(fp,"demo");
fclose(fp);
fp=fopen("demo.txt","r");
while((c=fgetc(fp))!=EOF)
printf("%c",c);
fclose(fp);
return 0;
}
a. Compilation Error
b. demo
c. NULL
d. demo.txt
a) A character string containing the name of the file & the second argument is the mode
b) A character string containing the name of the user & the second argument is the mode
c) A character string containing file pointer & the second argument is the mode
d) None of the mentioned
a. EOF
b. NULL
c. Run-time Error
d. None of the above
#include <stdio.h>
int main(){
FILE *fp;
char *str;
fp=fopen("demo.txt","r");// demo.txt :you are a good programmer
while(fgets(str,6,fp)!=NULL)
puts(str);
fclose(fp);
return 0;
}
a. you are a good programmer
b. e a good programmer
c. you ar
d. you are
83) How many times will the loop run for the following code?
a. 3 times
b. 2 times
c. 4096 times
d. Infinite
84) What will be the output for the following code?
a. 0
b. 1
c. garbage value
d. None
85) What does strcpy(s1,s2) do?
a. copies s1 string into s2
b. copies s2 string into s1
c. copies both s1 and s2
d. None of these
86) Choose correct statements about pass by value in c program.
a. Pass By Value copies the variable value in one more memory location
b. Pass By Value does not use Pointers
c. Pass By Value protects your source or original variables from changes in outside
functions or called functions
d. All the above
87) Local variables are stored in an area called__________.
a. Heap
b. Permanent storage area
c. Free memory
d. Stack
88) What will be the output for the code?
a. Garbage value
b. 30
c. 20
d. 657458
89) Which mode is better to open an existing file for both reading and writing?
a. “w”
b. “w+”
c. “r+”
d. “a+”
90) Select a function which is used to read a single character from a file at a time?
a. fputc( )
b. fscanf( )
c. fputs( )
d. fgetc( )
91) What will be the output for the following code?
a. Error occurs
b. 11i
c. 6 + 8i
d. 5 + 6i
92) Which of them is valid for malloc function?
a. malloc(400)
b. malloc(50,sizeof(int))
c. malloc(50*sizeof(int))
d. a and c
93) Which of the following is the correct syntax to send an array as a parameter to a C function?
a) Both func(&array) and func(*array);
b) Both func(#array) and func(&array);
c) Both func(array) and func(&array);
d) Both func(array[size]) and func(*array);
94) What are the elements present in the array of the following C code?
96) Which of the following c statement will calculate the correct size of an array of 10
integers?(Assuming the declaration as int a[10];)
a) sizeof(a[10]);
b) sizeof(*a);
c) sizeof(a);
d) sizeof(&a);
a) 5
b) 9
c) 10
d) 11
98) What is the maximum number of elements that can be stored in an array in C?
a) Depends on memory
b) 256
c) 1000
d) unlimited
int arr2[3]={9};
printf(“%d %d”,arr1[1],arr2[2]);
a) 2,0
b) 3,0
c) 2,9
d) 3,9
100) Array is an example of ------- type memory allocation.
a) Compile time
b) Run time
c) Both A and B
d) None of the above