0% found this document useful (0 votes)
59 views28 pages

MCQ Model Questions

model questions for exam

Uploaded by

ribakej513
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views28 pages

MCQ Model Questions

model questions for exam

Uploaded by

ribakej513
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

100 practice model question for MCQ Exam

1. What is the output of the following code?


#include <stdio.h>
int main() {
int x, y = 6, z = 6;
x = y == z;
printf("%d", x);
return 0;
}

A) 0
B) 1
C) 6
D) compiler error

2. What is the output of the following program?


#include <stdio.h>
void main() {
int a=5, b=6;
int result1 = a|b;
int result2 = a&b;
printf("%d and %d",result2,result1);
}

A) 5 and 6
B) 7 and 4
C) 4 and 7
D) compile error

3) What is the output of the following program?


#include <stdio.h>
void main()
{
int x = 5 * 9 / 3 + 9;
}
a. 24
b. 3.75
c. 3
d. 19

4) What is the output of d, a, b?


#include <stdio.h> //Program 1
int main()
{
int d, a = 1, b = 2;
d = a++ + ++b;
printf("%d, %d, %d", d, a, b);
}

a. 5,2,3
b. 4,2,3
c. 4,1,3
d. Error

5) Which is the correct format specifier for long long int?


a. %llf
b. %ld
c. %LLD
d. %lld

6) How many bytes does float take?


a. 8 bytes
b. 10 bytes
c. 1 byte
d. 4 bytes

7) Which of the following is true for variable names in C?


a) They can contain alphanumeric characters as well as special characters
b) It is not an error to declare a variable to be one of the keywords(like goto, static)
c) Variable names cannot start with a digit
d) Variable can be of any length

8) What will be the output of the following C code?

#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

9) What will be the output of the following code snippet?


int x = 5;
printf("%d\n", ++x);
a. 5
b. 6
c. 4
d. Compiler error

10) What is the value of ‘x’ after the execution of ‘x = 5%2;’ in C?


a. 2
b. 2.5
c. 1
d. 0.5

11) How many times will the following loop execute?


int x = 10;
while (x++ > 10) {
printf("Hello ");
}

a. 0 times
b. 9 times
c. 10 times
d. Infinite times

12) What is the output of the following code?


int i = 5;
do {
printf("%d ", i--);
} while (i > 0);

a. 54321
b. 5432
c. 543
d. 543210

13) For the following loop, when the value is “4”, jump directly to the next value.

for(int i = 0; i < 10; i++) {


if ( i == 4) {
_____ ;
}
printf(“%d\n”, i);
}

14) Add the correct format specifier in the blank below:


char value = ‘S’;
printf(“____”, value);

15) Which is the correct way for initializing an array of char?


a. Char array[ ] =”Sita”;
b. char array[ ]= ‘Sita’;
c. char array[10] = “Sita”;
d. char array=”Sita”;

16) What is the output of the program?


#include <stdio.h>
#include <stdbool.h>
int main() {
while (true) {
printf("Ram");
}
return 0;
}

a. Ram
b. Compile error
c. Ram is printed unlimited number of times
d. None of the above

17) What is the output of the following program?


#include <stdio.h
float isOdd(int n){
if(n%2==1){
return 1;
}else{
return 0;
}
}
void main() {
printf("%f",isOdd(7));
}
a. true
b. 1
c. 1.000000
d. None

18) What is the purpose of a function prototype in C language?


a. To declare the function name and its return type.
b. To define the implementation of a function.
c. To declare the return type of the function.
d. To declare the function name, its parameter types and return type.

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.

20) Which of the following is true about recursive functions in C language?


a. A recursive function cannot call itself.
b. A recursive function must have a base case to terminate the recursion.
c. A recursive function must have a return type of void.
d. A recursive function cannot be called from another function.

21) Which of the following is true about function arguments in C language?


a. Function arguments are always passed by value.
b. Function arguments are always passed by reference.
c. Function arguments can be passed by value or by reference.
d. Function arguments can be passed by value, not by reference

22) What is the output of the following program?

#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;
}

a. a in funct is 6,a in main function is 6


b. a in funct is 36,a in main function is 36
c. a in funct is 36,a in main function is 10
d. a in funct is 36,a in main function is 6

23) What is the output of the following program?


#include <stdio.h>
int funct(int a){
a= a*6;
printf("a in funct is %d,",a);
return a;
}
int main(){
int a=6;
a= funct(a);
printf("a in main function is %d ",a);
return 0;
}
a. a in funct is 6,a in main function is 6
b. a in funct is 36,a in main function is 36
c. a in funct is 36,a in main function is 10
d. a in funct is 36,a in main function is 6

24) Which of the following is a correct format for declaration of function?


a) return-type function-name(argument type);
b) return-type function-name(argument type){}
c) return-type (argument type)function-name;
d) all of the mentioned

25) The value obtained in the function is given back to main by using ________ keyword.
a. static
b. return
c. new
d. volatile

26) What will be the value of a and b?

#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

27) What will be the value of a?


#include <stdio.h>
void function() {
char ch[10] = "abcdefghij";
int a= 0;
for(int i = 0; i < 10; i++) {
a += (ch[i] - 'a');
}
printf("%d", a);
}
int main() {
function();
return 0;
}

a. 100
b. 36
c. 45
d. 20

28) What will be the output of the program?

#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

29) What will be the output of the program?

#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

30) What is the correct way to write actual parameters?


a. Int sum=sumofnum(a,b);
b. int sum = sumofnum(int a,int b);
c. int sum = sumofnum( a, b);
d. none

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

33) What will be the output of the following code?


#include <stdio.h>
void m(int k)
{
printf("hi");
}
void m(double k)
{
printf("hello");
}
void main()
{
m(3);
}
a. hi
b. hello
c. Compile time error
d. Nothing

34) Which of the following function declarations 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

35) What is the output of the following program?


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

a. 555
b. 500
c. 5(garbage)(garbage)
d. (garbage)(garbage)5

36) What is the output of the following program?

#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

37) What is the output of the following program?


#include <stdio.h>
int main()
{
int a[5] = {11,22,33,44,55};
int *p;
p = &a[0];
p++;
printf("%d, %d",*p,*(p+1));
return 0;
}

a. 11, 22
b. 22, 33
c. 11, 33
d. 22, 44

38) In c programming, sizeof() function returns:


a. The length of an array in integer
b. The bytes size required to allocate in memory
c. The array values one by one
d. None of the above

39) What is the output of the following program?

#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

40) Which function will you choose to join two words?


a) strcpy()
b) strcat()
c) strlen()
d) strcmp()

41) How to find the length of an array in C?


a. sizeof(a[0])
b. sizeof(a)/sizeof(a[0])
c. sizeof(a)*sizeof(a[0])
d. sizeof(a)

42) How to initialize a list of strings in an array?


a. Char [5][20]={“ram”,”shyam”,”hari”,”sita”,”gauri”};
b. char array[20][5]={“ram”,”shyam”,”hari”,”sita”,”gauri”};
c. char array[5][20]={“ram”,”shyam”,”hari”,”sita”,”gauri”};
d. char array[5][20]={ram,shyam,hari,sita,gauri};

43) What will be the output of the program?


#include <stdio.h>
void main(){
int *ptr=10;
printf("Value of ptr:%d",*ptr);
}
a. 10
b. Segmentation fault
c. Compilation error
d. 0

Look at the following table and answer the following questions. Addresses and values are
provided for the respective variables used in the program.

44) What is the output of the following code?


#include <stdio.h>
int main(){
int a=2;
int *p;
int *q;
p=&a;
q=&p
printf(“%d, %d”, p,q);
return 0;
}

a. 50, 200
b. 50, 100
c. 100, 50
d. 2, 50

45) What is the output of the following code?

#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. int *p= (int*) malloc(25* sizeof(int));


b. char *p= (char*) malloc(100* sizeofchar());
c. both a) and b)
d. None of the above.

48) How to prevent a dangling pointer -------------------------- ?

a)ptr==NULL;
b)ptr=NULL;
c)ptr==0;
d)ptr=0;

49) What is the output of this program?

#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

50) What is the problem with the following code?

#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

51) Fill the black area with appropriate code:


#include<stdio.h>
struct marks{
float math;
float science;
float social;
};
struct student{
int roll;
char name[20];
struct marks m;
};
void main(){
struct student s={23,"Susan",{59.55,45,64}};
%f s.m.social
printf("Marks in social = ____", __________);
}

52) Structure is a collection of:


a. Similar data types
b. Different data types
c. Values
d. None of the above

53) What will be the output for the following code?


#include<stdio.h>
#include<string.h>
typedef struct Student{
int roll;
char name[30];
float marks;
} student;
void main(){
student s[5]={{1,"Alice",55},{33,"Bob",40},{2,"Harry",99},{4,"Ram",30}};
student *ptr;
ptr = &s[3];
int i;
printf("%f",ptr->marks);
}
a. 55.000000
b. 40.000000
c. 99.000000
d. 30.000000

54) What will be the output for the following code?


#include<stdio.h>
#include<string.h>
typedef struct Student{
int roll;
char name[30];
float marks;
} student;
void main(){
student s[5]={{1,"Alice",55},{33,"Bob",40},{2,"Harry",99},{4,"Ram",30},{5,"Sita",80}};
student *ptr;
ptr = &s[0];
int i;
ptr++;
printf("%f",ptr->marks);
}
a. 55
b. 40.000000
c. 99
d. 55.000000

55) What will be the output for the following code?


#include<stdio.h>
typedef struct {
char name[20];
float salary;
}emp;
void main(){
emp e[5] = {{"Bob",50000},{"Alice",25000},{"Robin",5000}};
emp *p;
p = &e[0];
p = p+1;
printf("%s",p->name);
}
a. Bob
b. Alice
c. Robin
d. None

56) What will be the output for the following code?


#include<stdio.h>
struct data{
int lower = 0;
int upper = 3;
}range;

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

57) What is the output of the following program?

#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;

59) What is the output of the following program?

#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

60) What is the output of the following program?


#include <stdio.h>
#include <string.h>
struct student
{
char name[4];
};
void main()
{
struct student s, m;
strcpy(s.name,"IT");
m = s;
printf("%s, %s", s.name, m.name);
}

a. IT, Garbage Value


b. Compilation Error
c. Garbage Value, IT
d. IT, IT

61) Choose a correct statement about C structure elements?


a. Structure elements are stored in register memory locations
b. Structure elements are stored in contiguous memory locations
c. Structure elements are stored on random free memory locations
d. None of the above

62) What is the output of the following code?

#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)

64) What will be the output of the following code?

#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

65) What will be the output for the following code?


//Suppose a file test.txt contains “Welcome to Herald College” inside the file.
void main(){
FILE *fptr;
char a,b,c;
fptr = fopen("test.txt","r");
a = fgetc(fptr);
b = fgetc(fptr);
c = fgetc(fptr);
printf ("%c%c%c",a,b,c);
fclose(fptr);
}
a. WWW
b. Wel
c. abc
d. Error

66) What will be the output for the following code?


#include<stdio.h>
void main(){
char s[10]="Welcome to Herald.";
fprintf(stdout,"%s",s);
}
a. Welcome to Herald.
b. Welcome to
c. Welcome t
d. Welcome to H

67) What is the output of the following C program?


#include <stdio.h>
void main(){
FILE *fp;
fp = fopen("test.txt", "w");
fprintf(fp, “ABC");
fclose(fp);
fp = fopen("test.txt", "r");
char ch = fgetc(fp);
while (!feof(fp)){
printf("%c", ch);
ch = fgetc(fp);
}
}
a. AAA
b. CCC
c. BBB
d. ABC

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

69) What will be in demo.txt after executing the following code?


/* demo.txt contains "abc"*/
#include <stdio.h>
int main(){
FILE *f;
char s[20] = "ABC";
f = fopen("demo.txt","r");
fprintf(f,"%s",s);
}
a. abc
b. abcABC
c. ABC
d. Error

70) When fopen() is not able to open a file, it returns


a. EOF
b. NULL
c. Runtime Error
d. Compiler Dependent

71) A mode which is used to open an existing file for both reading and writing ______
a) "w"
b) "r+"
c) "a+"
d) "w+"

72) Select a function which is used to write a string to a file ______


a) pits()
b) putc()
c) fputs()
d) fgets()

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()

74) What is the output of the following program?


#include <stdio.h>
int main(){
char c;
FILE *fp;
fp=fopen("demo.txt","r");
while((c=fgetc(fp))!=EOF)
printf("%c",c);
fclose(fp);
return 0;
}

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

76) The first and second arguments of fopen() are

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

78) When fopen() is not able to open the file

a. EOF
b. NULL
c. Run-time Error
d. None of the above

79) What is the output of this program?

#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

80) The data of the file stored in?


a. Ram
b. Rom
c. Hard disk
d. None

81) Select a function which is used to write a string to a file?


a. puts()
b. putc()
c. fputs()
d. fputc()

82) FILE is of type ______


a) int type
b) char * type
c) struct type
d) None of the mentioned

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?

int array[5] = {5};


a) 5, 5, 5, 5, 5
b) 5, 0, 0, 0, 0
c) 5, (garbage), (garbage), (garbage), (garbage)
d) (garbage), (garbage), (garbage), (garbage), 5
95) What is the data type of the array passed from the command line into the main() function in C?
a) char arr[];
b) char *arr[];
c) char **arr[];
d) char arr[][];

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);

97) What is the highest index for an array with 10 elements in C?

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

99) Consider the following array declaration in the C language:

int arr 1[] ={2,3};

int arr2[3]={9};

what will be the ouput of the following print statement?

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

You might also like