CS201 | MID Term |mcq by moaaz and asad with reference

CS201 MID  TERM   A  DIRECTION  TO  PASS  INTRODUCTION  TO  PROGRAMMING 

CS201  MIDTERM  MCQS  MEGA  FILE 

 

Question

In order to get 256 from the number 2568 we divide this number by 10 and take,

► Its remainder

► The number

► Its quotient

► Its divisor

 

Question

The correct syntax of do-while loop is,

► (condition ) while; do { statements; };

► { statements; } do-while ();

► while(condition); do { statements; };

► do { statements; } while (condition);

 

Question

Which of the following function(s) is/are included in stdlib.h header file?

► double atof(const char *nptr)

► int atoi(const char *nptr)

► char *strcpy ( char *s1, const char *s2)

► 1 and 2 only (Pg 191)

 

Question

If the break statement is missed in switch statement then,

► The compiler will give error

► This may cause a logical error (Pg 76)

► No effect on program

► Program stops its execution

 

Question

The data type before a function name represents its,

► Return Type ( Pg 499)

► Function data

► Function arguments

► Function name

 

Question

Member function tellg() returns the current location of the _____________ pointer.

► tellptr()

► write()

► seekg()

► get() (Pg 215)

 

Question

What does 5 | 6 , evaluate to in decimal where ‘|’ is bitwise OR operator?

3

4

5

7

5 | 6 =

0 1 0 1

0 1 1 0

--------

0 1 1 1 = 7

 

Question

C is widely  known as development language of _______ operating system.

► Linux

► Windows

► Unix (Pg 12)

► Mac OS

 

Question

 What will be  the result of arithmetic expression 6+27/3*3?

► 33

► 45

► 9

 

Question

How many  bytes are occupied by declaring following array of characters?

char str[] = “programming”;

► 10

► 11

► 12

► 13

 

Question

What will be

the correct syntax for initialization of pointer ptr with string "programming"?

► char ptr = ’programming’ ;

► char *ptr = “programming” ;

► char *ptr = ‘programming’ ;

► *ptr = “programming” ;

pg 166

array element in each array initialized with a single character enclosed in single quote.

pg 21

While assigning a character value to a char type variable single quotes are used around the character

as ‘a’.

 

Question

What will be the result of expression x%= 2, if x = 7?

x = 1

x = 3

x = 7

x = 2

 

Question

UNIX has been developed in ________ language.

JAVA

B

C (pg 12)

FORTRAN

 

Question

Declaring structures does not mean that memory is allocated.

True (Pg 229)

False

Question

What will be the value of i and j in the following code segment?

int i, j ;

int x[5] = {2, 3, 4, 8, 9} ;

int *ptr =&x[2];

i = (*ptr)++ ;

j = *ptr++ ;

i = 5, j = 5

i = 5, j = 8

i = 4, j = 8

i = 5, j = 9

 

Question

When an array element is passed to a function, it is passed by ----------------.

 reference (Pg 266)

 data type

 value

 data

When we pass ordinary variables to functions, they are passed by value because of the default

behavior. But when an array is passed to a function, the default behavior changes and array is passed

by reference

Question

What is the output of the following statement?

int i = 2.5; do { cout i * 2; } while (i > 3 && i < 10);

(a) 510

(b) 5

(c) 48

(d) error

 

Question

What does !(7) evaluate to in decimal where ! is a NOT operator?

(a) 7

(b) 8

(c) 9

(d) 10

Question

The condition in while loop may contain logical expression but not relational expression.

(a) True

(b) False

 

Question

Searching is easier when an array is already sorted

(a) True

(b) False

 

Question

If an array has 100 elements, what is allowable range of subscripts?

(a) 0 - 99

(b) 1 - 99

(c) 0 - 100

(d) 1 – 100

 

Question

What will be the value of ‘a’ and ‘b’ after executing the following statements?

a = 3;

b = a++;

(a) 3, 4

(b) 4, 4

(c) 3, 3

(d) 4, 3

 

Question

What will be the correct syntax to initialize all elements of two-dimensional array to value 0?

(a) int arr[2][3] = {0,0} ;

(b) int arr[2][3] = {{0},{0}} ;

(c) int arr[2][3] = {0},{0} ;

(d) int arr[2][3] = {0} ;

 

Question

Which of the following functionreturns the size of a string variable?

(a) strlength()

(b) stringlen()

(c) strlen()

(d) strLength()

 

When applied to a character array, the strlen function returns the length of the string stored there

Question

What will be the range of numbers generated by function rand () % 9?

(a) 0 to 9

(b) 1 to 9

(c) 0 to 8

(d) 1 to 8

 

Question

Computer can understand only machine language code.

(c) True

(d) False

 

Question

What does 5 ^ 6 , evaluate to in decimal where ‘^’ is Exclusive OR operator?

(a) True

(b) False

Detail:-

It mean

5 = 0101

6 = 0110

5 ^ 6 = 0011

If both input is same then the output is 0 and if different then output is 1

 

Question

If the file is not properly closed in the program, the program ____________.

(a) Terminate normally

(b) Indicate Runtime error

(c) Indicate Compile time error

(d) Crashes

Eventually run out of file handles and/or memory space and crash.)

 

Question

Which of the following header file include string conversion functions?

(a) string.h

(b) stdlib.h (Pg 190)

(c) ctype.h

(d) sconvert.h

Question

A precise sequence of steps to solve a problem is called

Ø Statement

Ø Program

Ø Utility

Ø Routine

 

Question

The Compiler of C language is written in

Ø Java Language

Ø UNIX

Ø FORTRON Language

Ø C Language

 

Question

Initialization of variable at the time of definition is,

Ø Must

Ø Necessary

Ø Good Programming

Ø None of the given options

 

Question

In if structure the block of statements is executed only,

Ø When the condition is false

Ø When it contain arithmetic operators

Ø When it contain logical operators

Ø When the condition is true

 

Question

Dealing with structures and functions passing by reference is the most economical method

Ø True

Ø False

 

Question

Pointer is a variable which store,

Ø Data

Ø Memory Address

Ø Data Type

Ø Values

 

Question

Preprocessor program perform its function before ______ phase takes place.

Ø Editing

Ø Linking

Ø Compiling

Ø Loading