[go: up one dir, main page]

0% found this document useful (0 votes)
73 views30 pages

Semester - I (Ay 2020 - 21) Online Test Mcqs

This document contains a practice test for a Fundamentals of Data Structures course. It includes 36 multiple choice questions covering topics like pointers, arrays, strings, sorting algorithms, and data structures. The questions test students' understanding of concepts like complexity analysis, data structure properties, pointer operations, and standard library functions.

Uploaded by

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

Semester - I (Ay 2020 - 21) Online Test Mcqs

This document contains a practice test for a Fundamentals of Data Structures course. It includes 36 multiple choice questions covering topics like pointers, arrays, strings, sorting algorithms, and data structures. The questions test students' understanding of concepts like complexity analysis, data structure properties, pointer operations, and standard library functions.

Uploaded by

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

Hope Foundation’s

International Institute of Information Technology, Pune


Department of Computer Engineering

Semester - I (AY 2020 - 21)


Online Test MCQs

Class: SE (Comp. Engg.) Subject: Fundamentals of Data Structures

Unit-III

Q.1 The following program fragment (1M)

int *a;
*a = 7;

A) assigns 7 to a
B) results in compilation error
C) assigns address of a as 7
D) segmentation fault

Q.2 The complexity of Bubble sort algorithm is (1M)

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

Q.4 Determine which of the following is a valid character constant (1M)

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.6 A variable P is called pointer if (1M)

A) P contains the address of an element in DATA


B) P points to the address of first element in DATA
C) P can store only memory addresses
D) P contain the DATA and the address of DATA

Q.7 Which of the following data structure store the homogeneous data elements? (1M)

A) Arrays
B) Records
C) Pointers
D) None

Q.8 The difference between linear array and a record is (1M)

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

Q.9 Which of the following statement is false? (1M)


A) Arrays are dense lists and static data structure
B) Data elements in linked list need not be stored in adjacent space in memory
C) Pointers store the next data element of a list
D) Linked lists are collection of the nodes that contain information part and next pointer

Q.10 Choose the correct statements. (1M)

A) Internal sorting is used if the number of items to be sorted is very large.


B) External sorting is used if the number of items to be sorted is very small.
C) External sorting needs auxiliary storage
D) Internal sorting needs auxiliary storage
Q.11 A sorting technique that guarantees that records with the same primary key occurs in the
same order in the sorted list as in the original unsorted list is said to be (1M)

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

Q.14 What is the following code segment doing? (1M)

Void fn( )
{
char c;
gets(c);
if (c != ‘\n’)
{
fn( );
puts(c);
}
}

A) The string entered is printed as it is.


B) The string entered is printed in reverse order.
C) It will go in an infinite loop.
D) It will print an empty line.

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) Representation of NULL pointer


B) Representation of void pointer
C) Error
D) None of above

Q.20 In which header file is the NULL macro defined? (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.23 A pointer is (1M)

A) A keyword used to create variables


B) A variable that stores address of an instruction
C) A variable that stores address of other variable
D) All of the above

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

Q.27 How will you print \n on the screen? (1M)

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

A) It will print nothing.


B) -3
C) -2
D) 1
E) Compiler error

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

A) Nesting of structure is not allowed in c.


B) It is necessary to initialize the member variable.
C) Inner structure must have name.
D) Outer structure must have name.
E) There is not any error.

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) All of them let you define new values


B) All of them let you define new data types
C) All of them let you define new pointers
D) All of them let you define new structures

Q.44 A union cannot be nested in a structure (1M)


A) True
B) False

Q.45 Nested unions are allowed (1M)


A) True
B) False

Q.46 Bit fields CANNOT be used in union. (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

Q.48 Which of the following statement is True? (1M)


A) User has to explicitly define the numeric value of enumerations
B) User has a control over the size of enumeration variables.
C) Enumeration can have an effect local to the block, if desired
D) Enumerations have a global effect throughout the file.

Q.49 What will be the output of the program? (2M)


#include<stdio.h>
int main()
{
union a
{
int i;
char ch[2];
};
union a u;
u.ch[0]=3;
u.ch[1]=2;
printf("%d, %d, %d\n", u.ch[0], u.ch[1], u.i);
return 0;
}

A) 3, 2, 515
B) 515, 2, 3
C) 3, 2, 5
D) 515, 515, 4

Q.50 What will be the output of the program? (2M)


#include<stdio.h>
int main()
{
Union var
{
int a, b;
};
Union var v;
v.a=10;
v.b=20;
printf("%d\n", v.a);
return 0;
}

A) 10
B) 20
C) 30
D) 0

Q.51 What will be the output of the program? (2M)


#include<stdio.h>
int main()
{
struct value
{
int bit1:1;
int bit3:4;
int bit4:4;
}
bit={1, 2, 13};
printf("%d, %d, %d\n", bit.bit1, bit.bit3, bit.bit4);
return 0;
}

A) 1, 2, 13
B) 1, 4, 4
C) -1, 2, -3
D) -1, -2, -13

Q.52 What will be the output of the program? (2M)


#include<stdio.h>
int main()
{
int i=4, j=8;
printf("%d, %d, %d\n", i|j&j|i, i|j&j|i, i^j);
return 0;
}

A) 12, 12, 12
B) 112, 1, 12
C) 32, 1, 12
D) -64, 1, 12

Q.53 What will be the output of the program? (2M)


#include<stdio.h>
int main()
{
struct byte
{
int one:1;
};
struct byte var = {1};
printf("%d\n", var.one);
return 0;
}

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

Q.54 What will be the output of the program? (2M)


#include<stdio.h>
struct course
{
Int courseno;
Char coursename[25];
};
int main()
{
struct course c[] = { {102, "Java"},
{103, "PHP"},
{104, "DotNet"}
};
printf("%d ", c[1].courseno);
printf("%s\n", (*(c+2)).coursename);
return 0;
}

A) 103 DotNet
B) 102 Java
C) 103 PHP
D) 104 DotNet

Q.55 Point out the error in the program (1M)


Struct emp
{
Int ecode;
Struct emp *e;
};

A) Error: in structure declaration


B) Linker Error
C) No Error
D) None of above

Q.56 Point out the error in the program (1M)


Typedef struct data mystruct;
struct data
{
int x;
mystruct *b;
};

A) Error: in structure declaration


B) Linker Error
C) No Error
D) None of above

Q.57 Point out the error in the program (2M)


#include<stdio.h>
int main()
{
struct a
{
float category:5;
char scheme:4;
};
printf("size=%d", sizeof(struct a));
return 0;
}

A) Error: invalid structure member in printf


B) Error in this float category:5; statement
C) No error
D) None of above
Q.58 Point out the error in the program (1M)

Struct emp
{
Int ecode;
Struct emp e;
};

A) Error: in structure declaration


B) Linker Error
C) No Error
D) None of above

Q.59 Point out the error in the program (2M)

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

A) Error: invalid structure member


B) Error: Floating point formats not linked
C) No error
D) None of above

Q.60 Point out the error in the program (1M)


#include<stdio.h>
int main()
{
union a
{
int i;
char ch[2];
};
union a z1 = {512};
union a z2 = {0, 2};
return 0;
}

A) Error: invalid union declaration


B) Error: in Initializing z2
C) No error
D) None of above

Q.61 Point out the error in the program (2M)

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

A) Prints: The structure are equal


B) Error: Structure cannot be compared using '=='
C) No output
D) None of above

Q.62 Point out the error in the program (1M)


#include<stdio.h>
int main()
{
union a
{
int i;
charch[2];
};
union a z1 = {512};
union a z2 = {0, 2};
return 0;
}

A) Error: invalid union declaration


B) Error: in Initializing z2
C) No error
D) None of above

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

Q.64 Point out the error in the program (2M)


#include<stdio.h>
int main()
{
struct bits
{
float f:2;
}bit;

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.65 Point out the error in the program (2M)


#include<stdio.h>
int main()
{
Struct emp
{
char name[25];
int age;
floatbs;
};
Struct emp e;
e.name = "Suresh";
e.age = 25;
printf("%s %d\n", e.name, e.age);
return 0;
}

A) Error: Lvalue required/incompatible types in assignment


B) Error: invalid constant expression
C) Error: Rvalue required
D) No error, Output: Suresh 25

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

1. u2 CANNOT be initialized as shown.


2. u1 can be initialized as shown.
3. To initialize char ch[] of u2 '.' operator should be used.
4. The code causes an error 'Declaration syntax error'

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;

A) Structure bolts is nested within structure engine. (1M)


B) Structure engine is nested within structure maruti.
C) Structure maruti is nested within structure engine.
D) Structure maruti is nested within structure bolts.

Q.69 Size of union is size of the longest element in the union


(1M)
A) Yes
B) No

Q.70 The elements of union are always accessed using & operator (1M)
A) Yes
B) No

Q.71 Will the following code work? (2M)


#include<stdio.h>
#include<alloc.h>
Struct emp
{
intlen;
char name[1];
};
int main()
{
Char newname[] = "Rahul";
Struct emp *p = (structemp *) malloc(sizeof(structemp) -1 +
strlen(newname)+1);

p->len = strlen(newname);
strcpy(p -> name, newname);
printf("%d %s\n", p->len, p->name);
return 0;
}

A) Yes
B) No

Q.72 A pointer union CANNOT be created (1M)


A) Yes
B) No

Q.73 Which of the following statements are correct? (1M)

1. A string is a collection of characters terminated by '\0'.


2. The format specifier %s is used to print a string.
3. The length of the string can be obtained by strlen().
4. The pointer CANNOT work on string.

A) 1, 2
B) 1, 2, 3
C) 2, 4
D) 3, 4

Q.74 Which of the following statement is correct? (1M)

A) strcmp(s1, s2) returns a number less than 0 if s1>s2


B) strcmp(s1, s2) returns a number greater than 0 if s1<s2
C) strcmp(s1, s2) returns 0 if s1==s2
D) strcmp(s1, s2) returns 1 if s1==s2
Q.75 What will be the output of the program? (1M)
#include<stdio.h>
#include<string.h>
int main()
{
char str1[20] = "Hello", str2[20] = " World";
printf("%s\n", strcpy(str2, strcat(str1, str2)));
return 0;
}

A) Hello
B) World
C) Hello World
D) WorldHello

Q.76 What will be the output of the program? (1M)

#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

Q.78 What will be the output of the program? (1M)


#include<stdio.h>
int main()
{
printf(5+"Good Morning\n");
return 0;
}

A) Good Morning
B) Good
C) M
D) Morning

Q.79 What will be the output of the program? (1M)

#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

Q.81 What will be the output of the program?


(1M)
#include<stdio.h>
int main()
{
printf("India", "BIX\n");
return 0;
}
A) Error
B) India BIX
C) India
D) BIX

Q.82 What will be the output of the program? (1M)


#include<stdio.h>
int main()
{
charstr[7] = "IndiaBIX";
printf("%s\n", str);
return 0;
}

A) Error
B) IndiaBIX
C) Cannot predict
D) None of above

Q.83 What will be the output of the program? (2M)


#include<stdio.h>
int main()
{
char *names[] = { "Suresh", "Siva", "Sona", "Baiju", "Ritu"};
int i;
char *t;
t = names[3];
names[3] = names[4];
names[4] = t;
for(i=0; i<=4; i++)
printf("%s,", names[i]);
return 0;
}

A) Suresh, Siva, Sona, Baiju, Ritu


B) Suresh, Siva, Sona, Ritu, Baiju
C) Suresh, Siva, Baiju, Sona, Ritu
D) Suresh, Siva, Ritu, Sona, Baiju

Q.84 What will be the output of the program? (1M)

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

Q.87 What will be the output of the program? (2M)

#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

Q.88 What will be the output of the program? (1M)


#include<stdio.h>
int main()
{
int i=3, *j, k;
j = &i;
printf("%d\n", i**j*i+*j);
return 0;
}

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

Q.90 What will be the output of the program? (2M)


#include<stdio.h>
#include<string.h>
int main()
{
static char str1[] = "dills";
static char str2[20];
static char str3[] = "Daffo";
int i;
i = strcmp(strcat(str3, strcpy(str2, str1)), "Daffodills");
printf("%d\n", i);
return 0;
}

A) 0
B) 1
C) 2
D) 4

Q.91 What will be the output of the program?


(1M)
#include<stdio.h>
#include<string.h>
int main()
{
static char s[] = "Hello!";
printf("%d\n", *(s+strlen(s)));
return 0;
}

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

Q.94 What is the output of this C code? (2M)


#include <stdio.h>
void foo(int*);
int main()
{
int i = 10;
foo((&i)++);
}
void foo(int *p)
{
printf("%d\n", *p);
}

A) 10
B) Some garbage value
C) Compile time error
D) Segmentation fault/code crash

Q.95 What is the output of this C code? (2M)


#include <stdio.h>
void foo(int*);
int main()
{
int i = 10, *p = &i;
foo(p++);
}
void foo(int *p)
{
printf("%d\n", *p);
}

A) 10
B) Some garbage value
C) Compile time error
D) Segmentation fault

Q.96 What is the output of this C code? (2M)


#include <stdio.h>
void foo(float *);
int main()
{
int i = 10, *p = &i;
foo(&i);
}
void foo(float *p)
{
printf("%f\n", *p);
}

A) 10.000000
B) 0.000000
C) Compile time error
D) Undefined behavior

You might also like