Semester - I (Ay 2020 - 21) Online Test Mcqs
Semester - I (Ay 2020 - 21) Online Test Mcqs
Unit-III
int *a;
*a = 7;
A) assigns 7 to a
B) results in compilation error
C) assigns address of a as 7
D) segmentation fault
A) O(n)
B) O(log n)
C) O(n2)
D) O(n log n)
Q.3 If an integer occupies 4 bytes and a character occupies 1 bytes of memory, each element of the
following structure would occupy how many bytes? (1M)
struct name
{
int age;
char name [20];
}
A) 5
B) 24
C) 21
D) 22
A) ‘\\’
B) ‘\0’
C) ‘xyz’
D) ‘\052’
Q.5 The process of production of customer list in alphabetical order falls under category of (1M)
A) Editing
B) Sorting
C) Updating
D) Calculating
Q.7 Which of the following data structure store the homogeneous data elements? (1M)
A) Arrays
B) Records
C) Pointers
D) None
A) An array is suitable for homogeneous data but the data items in a record may have different
data type
B) In a record, there may not be a natural ordering in opposed to linear array
C) A record form a hierarchical structure but a linear array does not
D) All of above
A) stable
B) consistent
C) external
D) linear
Q.12 The way a card game player arranges his cards as he picks them up one by one, is an example
of (1M)
A) bubble sort
B) selection sort
C) insertion sort
D) merge sort
Q.13 Which of the following sorting methods will be the best if number of swapping done, is the
only measure of efficiency? (1M)
A) Bubble sort
B) Selection sort
C) Insertion sort
D) Quick sort
Void fn( )
{
char c;
gets(c);
if (c != ‘\n’)
{
fn( );
puts(c);
}
}
Q.15 You have to sort a list L consisting of a sorted list followed by a few “random” elements. Which
of the following sorting methods would be especially suitable for such a task? (1M)
A) Bubble sort
B) Selection sort
C) Quick sort
D) Insertion sort
Q.16 Which of the following sorting methods would be most suitable for sorting a list which is
almost sorted (1M)
A) Bubble Sort
B) Insertion Sort
C) Selection Sort
D) Quick Sort
Q.17 The number of interchanges required to sort 5, 1, 6, 2, 4 in ascending order using Bubble Sort
is (1M)
A) 6
B) 5
C) 7
D) 8
Q.18 The complexity of multiplying two matrices of order m*n and n*p is (1M)
A) mnp
B) mp
C) mn
D) np
Q.19 What is (void*)0? (1M)
A) stdio.h
B) stddef.h
C) stdio.h and stddef.h
D) math.h
Q.21 If a variable is a pointer to a structure, then which of the following operator is used to access
data members of the structure through the pointer variable? (1M)
A) .
B) &
C) *
D) ->
Q.22 What would be the equivalent pointer expression for referring the array element a[i][j][k][l]
(2M)
A) ((((a+i)+j)+k)+l)
B) *(*(*(*(a+i)+j)+k)+l)
C) (((a+i)+j)+k+l)
D) ((a+i)+j+k+l)
Q.24 The operator used to get value at address stored in a pointer variable is (1M)
A) *
B) &
C) &&
D) ||
Q.25 Which of the following function sets first n characters of a string to a given character? (1M)
A) strinit()
B) strnset()
C) strset()
D) strcset()
Q.26 If the two strings are identical, then strcmp() function returns (1M)
A) -1
B) 1
C) 0
D) Yes
A) printf("\n");
B) echo "\\n";
C) printf('\n');
D) printf("\\n");
Q.28 The library function used to find the last occurrence of a character in a string is (1M)
A) strnstr()
B) laststr()
C) strrchr()
D) strstr()
Q.29 Which of the following function is used to find the first occurrence of a given string in another
string? (1M)
A) strchr()
B) strrchr()
C) strstr()
D) strnset()
Q.30 Which of the following function is more appropriate for reading in a multi-word string? (1M)
A) printf();
B) scanf();
C) gets();
D) puts();
Q.31 Which of the following function is correct that finds the length of a string? (2M)
A) intxstrlen(char *s)
{
int length=0;
while(*s!='\0')
{ length++; s++; }
return (length);
}
B) intxstrlen(char s)
{
int length=0;
while(*s!='\0')
length++; s++;
return (length);
}
C) intxstrlen(char *s)
{
int length=0;
while(*s!='\0')
length++;
return (length);
}
D) intxstrlen(char *s)
{
int length=0;
while(*s!='\0')
s++;
return (length);
}
(1M)
Q.32 What will be output if you will compile and execute the following c code?
void main(){
int i=320;
char *ptr=(char *)&i;
printf("%d",*ptr);
}
A) 320
B) 1
C) 64
D) Compiler error
E) None of above
Q.33 What will be output if you will compile and execute the following c code? (1M)
#define x 5+2
void main(){
int i;
i=x*x*x;
printf("%d",i);
}
A) 343
B) 27
C) 133
D) Compiler error
E) None of above
Q.34 What will be output if you will compile and execute the following c code? (1M)
void main(){
int i=4,x;
x=++i + ++i + ++i;
printf("%d",x);
}
A) 21
B) 18
C) 12
D) Compiler error
E) None of above
Q.35 What will be output if you will compile and execute the following c code? (2M)
void main(){
int a=2;
if(a==2){
a=~a+2<<1;
printf("%d",a);
}
else{
break;
}
}
Q.36 What will be output if you will compile and execute the following c code? (1M)
void main(){
int a=10;
printf("%d %d %d",a,a++,++a);
}
A) 12 11 11
B) 12 10 10
C) 11 11 12
D) 10 10 12
E) Compiler error
Q.37 What will be output if you will compile and execute the following c code? (1M)
void main(){
char *str="Hello world";
printf("%d",printf("%s",str));
}
A) 11Hello world
B) 10Hello world
C) Hello world10
D) Hello world11
E) Compiler error
Q.38 What will be output if you will compile and execute the following c code? (1M)
#include "stdio.h"
#include "string.h"
void main(){
char *str=NULL;
strcpy(str,"cquestionbank");
printf("%s",str);
}
A) cquestionbank
B) cquestionbank\0
C) (null)
D) It will print nothing
E) Compiler error
Q.39 What will be output if you will compile and execute the following c code? (2M)
void main()
{
int a=10,b=20;
char x=1,y=0;
if(a,b,x,y)
{
printf("EXAM");
}
}
A) XAM is printed
B) exam is printed
C) Compiler Error
D) Nothing is printed
Q.40 What will be output if you will compile and execute the following c code? (1M)
int * call();
void main(){
int *ptr;
ptr=call();
clrscr();
printf("%d",*ptr);
}
int * call(){
int a=25;
a++;
return &a;
}
A) 25
B) 26
C) Any address
D) Garbage value
E) Compiler error
Q.41 What is error in following declaration? (1M)
struct outer{
int a;
struct inner{
char c;
};
};
Q.42 What will be output if you will compile and execute the following c code? (1M)
void main(){
double far* p,q;
printf("%d",sizeof(p)+sizeof q);
}
A) 12
B) 8
C) 4
D) 1
E) Compiler error
Q.43 What is the similarity between a structure, union and enumeration? (1M)
A) True
B) False
Q.47 One of elements of a structure can be a pointer to the same structure. (1M)
C) True
D) False
A) 3, 2, 515
B) 515, 2, 3
C) 3, 2, 5
D) 515, 515, 4
A) 10
B) 20
C) 30
D) 0
A) 1, 2, 13
B) 1, 4, 4
C) -1, 2, -3
D) -1, -2, -13
A) 12, 12, 12
B) 112, 1, 12
C) 32, 1, 12
D) -64, 1, 12
A) 1
B) -1
C) 0
D) Error
A) 103 DotNet
B) 102 Java
C) 103 PHP
D) 104 DotNet
Struct emp
{
Int ecode;
Struct emp e;
};
#include<stdio.h>
int main()
{
Struct emp
{
char name[20];
float sal;
};
Struct emp e[10];
int i;
for(i=0; i<=9; i++)
scanf("%s %f", e[i].name, &e[i].sal);
return 0;
}
#include<stdio.h>
int main()
{
Struct emp
{
char n[20];
int age;
};
Struct emp e1 = {"Dravid", 23};
Struct emp e2 = e1;
if(e1 == e2)
printf("The structure are equal");
return 0;
}
Q.63 Which of the following is the correct way of declaring a float pointer: (1M)
A) float ptr;
B) *float ptr;
C) float *ptr;
D) None of above
printf("%d\n", sizeof(bit));
return 0;
}
A) 4
B) 2
C) Error: cannot set bit field for float
D) Error: Invalid member access in structure
Q.66 Which of the following statements correct about the below program? (1M)
#include<stdio.h>
int main()
{
union a
{
int i;
charch[2];
};
union a u1 = {512};
union a u2 = {0, 2};
return 0;
}
A) 1, 2
B) 2, 3
C) 1, 2, 3
D) 1, 3, 4
Q.67 Which of the following statements correctly assigns 12 to month using pointer variable pdt?
#include<stdio.h> (2M)
struct date
{
int day;
int month;
int year;
};
int main()
{
struct date d;
struct date *pdt;
pdt = &d;
return 0;
}
A) pdt.month = 12
B) &pdt.month = 12
C) d.month = 12
D) pdt->month = 12
Q.68 Which of the following statements correct about the below code?maruti.engine.bolts=25;
Q.70 The elements of union are always accessed using & operator (1M)
A) Yes
B) No
p->len = strlen(newname);
strcpy(p -> name, newname);
printf("%d %s\n", p->len, p->name);
return 0;
}
A) Yes
B) No
A) 1, 2
B) 1, 2, 3
C) 2, 4
D) 3, 4
A) Hello
B) World
C) Hello World
D) WorldHello
#include<stdio.h>
int main()
{
char p[] = "%d\n";
p[1] = 'c';
printf(p, 65);
return 0;
}
A) A
B) a
C) c
D) 65
(1M)
Q.77 What will be the output of the program?
#include<stdio.h>
#include<string.h>
int main()
{
printf("%d\n", strlen("123456"));
return 0;
}
A) 6
B) 12
C) 7
D) 2
A) Good Morning
B) Good
C) M
D) Morning
#include<stdio.h>
#include<string.h>
int main()
{
charstr[] = "India\0\BIX\0";
printf("%s\n", str);
return 0;
}
A) BIX
B) India
C) India BIX
D) India\0BIX
Q.80 What will be the output of the program If characters 'a', 'b' and 'c' enter are supplied as input?
#include<stdio.h> (2M)
int main()
{
void fun();
fun();
printf("\n");
return 0;
}
void fun()
(1M)
{
char c;
if((c = getchar())!= '\n')
fun();
printf("%c", c);
}
A) abcabc
B) bca
C) Infinite loop
D) cba
A) Error
B) IndiaBIX
C) Cannot predict
D) None of above
#include<stdio.h>
#include<string.h>
int main()
{
charstr[] = "India\0\BIX\0";
printf("%d\n", strlen(str));
return 0;
}
A) 10
B) 6
C) 5
D) 11
Q.85 It is necessary that the size of all elements in a union should be same (1M)
A) True
B) False
Q.86 How can you combine the following two statements into one? (1M)
char *p;
p = (char*) malloc(100);
A) char p = *malloc(100);
B) char *p = (char) malloc(100);
C) char *p = (char*)malloc(100);
D) char *p = (char *)(malloc*)(100);
#include<stdio.h>
int main()
{
static char *s[] = {"black", "white", "pink", "violet"};
char **ptr[] = {s+3, s+2, s+1, s}, ***p;
p = ptr;
++p;
printf("%s", **p+1);
return 0;
}
A) ink
B) ack
C) ite
D) let
A) 30
B) 27
C) 9
D) 3
Q.89 What will be the output of the program if the integer is 4 bytes long? (2M)
#include<stdio.h>
int main()
{
int ***r, **q, *p, i=8;
p = &i;
q = &p;
r = &q;
printf("%d, %d, %d\n", *p, **q, ***r);
return 0;
}
A) 8, 8, 8
B) 4000, 4002, 4004
C) 4000, 4004, 4008
D) 4000, 4008, 4016
A) 0
B) 1
C) 2
D) 4
A) 8
B) 0
C) 16
D) Error
Q.92 If the size of pointer is 32 bits What will be the output of the program? (1M)
#include<stdio.h>
int main()
{
char a[] = "Visual C++";
char *b = "Visual C++";
printf("%d, %d\n", sizeof(a), sizeof(b));
printf("%d, %d", sizeof(*a), sizeof(*b));
return 0;
}
A) 10, 2
2, 2
B) 10, 4
1, 2
C) 11, 4
1, 1
D) 12, 2
2, 2
Q.93 If the size of pointer is 4 bytes then What will be the output of the program? (1M)
#include<stdio.h>
int main()
{
char *str[] = {"Frogs", "Do", "Not", "Die", "They", "Croak!"};
printf("%d, %d", sizeof(str), strlen(str[0]));
return 0;
}
A) 22, 4
B) 25, 5
C) 24, 5
D) 20, 2
A) 10
B) Some garbage value
C) Compile time error
D) Segmentation fault/code crash
A) 10
B) Some garbage value
C) Compile time error
D) Segmentation fault
A) 10.000000
B) 0.000000
C) Compile time error
D) Undefined behavior