Paper Tayyari

Midterm PreparationMidterm ki tayyari

Syllabus: lectures 1–24. Past-paper MCQs are shown first.Syllabus: lecture 1–24. Past paper ki MCQs pehle dikhai gayi hain.

184 MCQs · 15 short · 12 long questions · 184 MCQs from past papers184 MCQs · 15 short · 12 long sawal · 184 MCQs past papers se

Start mock testMock test shuru karein
DoneHal kiye 0/184
– correctsahi
1.
★ Final term solved MCQs (Moaaz & Asad)Lecture 1

Skill(s) that is/are needed by programmer's _______________________.

  1. APaying attention to detail
  2. BThink about the reusability
  3. CThink about user interface
  4. DAll of the given options

The course lists all these as required programmer skills.

2.
★ Final term 2017 (paper 3)Lecture 2

In year ____, C was approved as a standard language worldwide.

  1. A1988
  2. B1967
  3. C1989
  4. D1986

ANSI approved the C standard in 1989 (ANSI C / C89).

3.
★ Final term 2017 (paper 3)Lecture 2

The C language was developed in late 60's and early 70's, in ____.

  1. ARichards Laboratories
  2. BMicrosoft Laboratories
  3. CBell Laboratories
  4. DIBM Laboratories

Dennis Ritchie developed C at AT&T Bell Laboratories.

4.
★ Final term solved MCQs (Moaaz & Asad)Lecture 2

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

  1. ALinux
  2. BWindows
  3. CUnix
  4. DMac OS

C became known as the language in which UNIX was written.

5.
★ Final term solved MCQs (Moaaz & Asad)Lecture 2

UNIX has been developed in ________ language.

  1. AJAVA
  2. BB
  3. CC
  4. DFORTRAN

UNIX was rewritten in C, which was created for it.

6.
★ Final term solved MCQs (Moaaz & Asad)Lecture 2

There are mainly -------------------- types of software

  1. ATwo
  2. BThree
  3. CFour
  4. DFive

Software is mainly system software and application software.

7.
★ Solved MCQs collectionLecture 2

Compiler is a

  1. ASystem software
  2. BApplication Software
  3. CDriver
  4. DEditor

A compiler is a programming tool classed as system software.

8.
★ Solved MCQs collectionLecture 2

Operating System is

  1. AAn application software
  2. BSystem Software
  3. CComputer Language
  4. DInterpreter

The operating system is system software.

9.
★ Past paper collectionLecture 2

In computer systems there are mainly ___________ type of softwares.

  1. A1
  2. B2
  3. C3
  4. D4

Software is mainly of two types: system software and application software.

10.
★ Past paper collectionLecture 4

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

  1. A10
  2. B40.5
  3. C42
  4. D41

/ and * go left to right first: 48/4 = 12, 12*3 = 36, then 6 + 36 = 42.

11.
★ Past paper collectionLecture 4

In the given expression which operator will be evaluated first? 10 + (6 / 2) - 2 * 3?

  1. A+
  2. B-
  3. C/
  4. D*

The expression inside parentheses, 6 / 2, is evaluated first.

12.
★ Past paper collectionLecture 4

What will be the value of the variable output in the given piece of code? double output = 0; output = (2 + 2) * 4 + 2 / (4 - 2);

  1. A15
  2. B17
  3. C12
  4. D11

(2+2)*4 = 16 and 2/(4-2) = 1, so output is 17.

13.
★ Final term solved MCQs (Moaaz & Asad)Lecture 5

In if structure the block of statements is executed only,

  1. AWhen the condition is false
  2. BWhen it contain arithmetic operators
  3. CWhen it contain logical operators
  4. DWhen the condition is true

The if block runs only when its condition evaluates to true.

14.
★ Past paper collectionLecture 5

What will be the value of variable "input" if the initial value of input is 67? if(input >= 50) input = input + 1; if(input <= 75) input = input + 2; else input = input - 1;

  1. A68
  2. B69
  3. C70
  4. D66

67 >= 50 gives 68; 68 <= 75 adds 2, giving 70.

15.
★ Past paper collectionLecture 5

When the if statement consists more than one statement then enclosing these statement in curly braces is,

  1. ANot required
  2. BGood programming
  3. CRelevant
  4. DMust

Without braces only the first statement belongs to the if.

16.
★ Past paper collectionLecture 6

A ___________ structure specifies that an action is to be repeated while some condition remains true.

  1. AControl
  2. BLogical
  3. CRepetition
  4. DRelational

A repetition (loop) structure repeats an action while a condition is true.

17.
★ Final term 2017 (paper 2)Lecture 8

When break statement is encountered in switch statement, it ______

  1. AStops the entire program
  2. BStops the execution of current statement
  3. CExits from switch statement
  4. DRepeats the switch statement

break transfers control to the statement after the switch block.

18.
★ Solved MCQs collectionLecture 8

If the break statement is missed in switch statement then,

  1. AThe compiler will give error
  2. BThis may cause a logical error
  3. CNo effect on program
  4. DProgram stops its execution

Without break, control falls through into the next case, which can cause a logical error.

19.
★ Past paper collectionLecture 8

What is the output of the following code, if the first case is true switch (var) { case 'a':cout<<"apple"<<endl; case 'b':cout<<"banana"<<endl; case 'm':cout<<"mango"<<endl; default: cout<<"any fruit"<<endl; }

  1. Aapple
  2. Bapple any fruit
  3. Capple banana mango any fruit
  4. Dnone of above

Without break, all statements from case 'a' onward run.

20.
★ Past paper collectionLecture 8

_________statement is used to terminate the processing of a particular case and exit from switch structure.

  1. Aif
  2. Bgoto
  3. Cbreak
  4. Dcontinue

break ends the current case and leaves the switch.

21.
★ Final term solved MCQs (Moaaz & Asad)Lecture 9

The return type of a function that do not return any value must be ________

  1. Afloat
  2. Bint
  3. Cvoid
  4. Ddouble

void declares that a function returns no value.

22.
★ Final term solved MCQs (Moaaz & Asad)Lecture 9

If the return type of a function is void then it means that it will,

  1. AReturn any type of data
  2. BReturn some specific type of data
  3. CReturn no data
  4. DReturn just character data

void means the function returns no value.

23.
★ Final term 2017 (paper 2)Lecture 11

What is the highest legal index for the following array? int arr[4]

  1. A4
  2. B3
  3. C2
  4. D1

Indexes run from 0 to size-1, so the last index is 3.

24.
★ Final term 2017 (paper 3)Lecture 11

Which of the following syntax will be used to initialize an array of size 5 of int data type to value 0?

  1. Aarr[5] = {0} ;
  2. Bint arr[5]= 0 ;
  3. Cint arr[5] = {0} ;
  4. Dint arr[] = 0 ;

An initializer list {0} sets the first element to 0 and the remaining elements are zero-initialized; the declaration needs the type.

25.
★ Final term solved MCQs (Moaaz & Asad)Lecture 11

In C/C++ if we define an array of size eight (8) i.e. int Arr [8]; then the last element of this array will be stored at,

  1. AArr[0]
  2. BArr[8]
  3. CArr[7]
  4. DArr[-1]

Indexes start at 0, so the last of 8 elements is Arr[7].

26.
★ Final term solved MCQs (Moaaz & Asad)Lecture 11

Suppose a program contains an array declared as int arr[100]; what will be the size of array?

  1. A0
  2. B99
  3. C100
  4. D101

The declared size is 100 elements (indexes 0 to 99).

27.
★ Final term solved MCQs (Moaaz & Asad)Lecture 14

There is a pointer variable named ptr of type int then address of which type of variable the ptr will store in it?

  1. Avariable of type char
  2. Bvariable of type short
  3. Cvariable of type int
  4. Dvariable of type double

An int pointer stores the address of an int.

28.
★ Solved MCQs collectionLecture 14

Dereferencing operator is represented by _______

  1. A*
  2. B+
  3. C–
  4. DNone of the given

The unary * operator dereferences a pointer.

29.
★ Solved MCQs collectionLecture 14

What will be the correct syntax for initialization of pointer ptr of type int with variable x?

  1. Aint ptr = &x ;
  2. Bint ptr = x ;
  3. Cint *ptr = &x ;
  4. Dint ptr* = &x ;

A pointer to int is declared with * and initialized with the address of x.

30.
★ Past paper collectionLecture 14

The statement cout << yptr will show the __________the yptr points to.

  1. AValue
  2. Bmemory address
  3. CVariable
  4. DNone of the given

Printing the pointer itself shows the address it holds.

31.
★ Past paper collectionLecture 14

_________ is used as a dereferencing operator.

  1. A*
  2. B+
  3. C-
  4. DNone of the above

The unary * operator gives the value at the address in a pointer.

32.
★ Solved MCQs collectionLecture 19

These functions seekg() and seekp() require an argument of type ____________ to let them know how many bytes to move forward or backward.

  1. Aint
  2. Bshort
  3. Clong
  4. Ddouble

The offset argument of seekg()/seekp() is a long value (stream offset), as taught in the handouts.

33.
★ Solved MCQs collectionLecture 19

We have opened a file stream myfile for reading (getting), myfile.tellg() gives us the current get position of the file pointer. It returns a whole number of type___________

  1. Along
  2. Bint
  3. Cshort
  4. Ddouble

tellg() returns the position as a long (stream position) value per the handouts.

34.
★ Final term 2017 (paper 3)Lecture 20

A structure brings together a group of ____.

  1. Asame data type
  2. Bdifferent data types
  3. Cconstants
  4. Dboth a, b

A structure is used to group related variables that can be of different data types.

35.
★ Final term solved MCQs (Moaaz & Asad)Lecture 20

To access the data members of structure _______ is used.

  1. Adot operator (.)
  2. B* operator
  3. CU operator
  4. DNone of given.

Structure members are accessed with the dot operator.

36.
★ Final term solved MCQs (Moaaz & Asad)Lecture 20

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

  1. ATrue
  2. BFalse

Passing a structure by reference avoids copying all of its members.

37.
★ Solved MCQs collectionLecture 20

A structure is a collection of _____________ under a single name.

  1. Avalues
  2. Bvariables
  3. Cdata
  4. DNone of the given

A structure groups related variables under one name.

38.
★ Solved MCQs collectionLecture 20

Most efficient method of dealing with structure variables is to define the structure globally

  1. ATrue
  2. BFalse

A globally defined structure type is visible to all functions that use it.

39.
★ Final term solved MCQs (Moaaz & Asad)Lecture 21

Which of the following is used with bit manipulation?

  1. ASigned integer
  2. BUn-signed integer
  3. CSigned double
  4. DUn-signed double

Bitwise operations are applied to integers, typically unsigned ones.

40.
★ Final term solved MCQs (Moaaz & Asad)Lecture 21

If most significant bit of un-signed number is 1 then it represents a positive number.

  1. ATrue
  2. BFalse

An unsigned number has no sign bit, so its value is never negative.

41.
★ Final term 2017 (paper 2)Lecture 23

A macro when takes arguments is called ______.

  1. Afunction
  2. Bprocedure
  3. Cparameterized macro
  4. Dsimple macro

A #define macro that takes arguments is a parameterized macro.

42.
★ Final term 2017 (paper 2)Lecture 23

Which of the following is NOT a preprocessor directive?

  1. A#error
  2. B#define
  3. C#line
  4. D#ndefine

#ndefine does not exist; #error, #define and #line are valid directives.

43.
★ Final term solved MCQs (Moaaz & Asad)Lecture 23

If we define an identifier with the statement #define PI 3.1415926 then during the execution of the program the value of PI __________.

  1. Acan not be replaced
  2. BNone of the given options
  3. CRemain constant.
  4. Dcan be changed by some operation

The preprocessor substitutes the constant text, so PI cannot change at run time.

44.
★ Final term solved MCQs (Moaaz & Asad)Lecture 23

All preprocessor directives are started with the symbol______.

  1. A*
  2. B+
  3. C@
  4. D#

Every preprocessor directive begins with #.

45.
★ Final term solved MCQs (Moaaz & Asad)Lecture 23

We can also do conditional compilation with preprocessor directives.

  1. ATrue
  2. BFalse

#if, #ifdef, #ifndef, #else and #endif provide conditional compilation.

46.
★ Final term solved MCQs (Moaaz & Asad)Lecture 23

Where we can include a header file in the program?

  1. Aany where
  2. Bin start
  3. Cat the end
  4. Dnone of the given options.

#include can appear anywhere, though it is normally placed at the top.

47.
★ Solved MCQs collectionLecture 23

Which one is the correct syntax for defining an identifier PI with preprocessor directive?

  1. A#define PI 3.1415926;
  2. B#define PI 3.1415926
  3. C#define PI = 3.1415926 ;
  4. D#define PI = 3.1415926

A #define uses name and replacement text with no = and no semicolon.

48.
★ Midterm Spring 2009Lecture 23

In C/C++ the #include is called,

  1. AHeader file
  2. BPreprocessor Directive
  3. CStatement
  4. DFunction

Lines starting with # are preprocessor directives.

49.
★ Past paper collectionLecture 23

Symbolic constant PI can be defined as:

  1. A#define PI 3.14 ;
  2. B#define PI 3.14
  3. C#define PI=3.14
  4. D# include pi= 3.14

#define takes the name and replacement text with no = and no semicolon.

50.
★ Final term solved paper (vuattach 1)

Which of the following is the correct way to declare a variable x of integer type?

  1. Ax int ;
  2. Binteger x ;
  3. Cint x;
  4. Dx integer

A declaration gives the type first, then the name: int x;

51.
★ Final term solved paper (vuattach 1)

Reserve words cannot be used as a variable name.

  1. ATrue
  2. BFalse

Keywords are reserved by the language and cannot be identifiers.

52.
★ Final term solved paper (vuattach 1)

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

  1. A0 to 9
  2. B1 to 9
  3. C0 to 8
  4. D1 to 8

The remainder after division by 9 is always from 0 to 8.

53.
★ Final term solved paper (vuattach 1)

Which of the following is the correct function call having array named student of 10 elements as a parameter.

  1. AaddRecord(student[]) ;
  2. BaddRecord(student) ;
  3. CaddRecord(student[10]) ;
  4. DaddRecord(*student) ;

An array is passed by its name only, which gives the address of its first element.

54.
★ Final term solved paper (vuattach 1)

Declaring structures does not mean that memory is allocated.

  1. ATrue
  2. BFalse

A structure declaration only defines a type; memory is used when a variable is created.

55.
★ Final term solved paper (vuattach 1)

Identifier is a name that can be given to variables, labels and functions.

  1. ATrue
  2. BFalse

Identifiers are user-chosen names for variables, functions and labels.

56.
★ Final term solved paper (vuattach 1)

Truth tables are used for analyzing ___________.

  1. Alogical expressions
  2. Barithmetic expressions
  3. Cboth logical and arithmetic expressions
  4. Dnone of the given options.

Truth tables list results of logical expressions for all input combinations.

57.
★ Final term solved paper (vuattach 6)

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

  1. A1
  2. B2
  3. C3
  4. D4

101 XOR 110 = 011, which is 3.

58.
★ Final term solved paper (vuattach 6)

Array is passed by value to a function by default.

  1. ATrue
  2. BFalse

An array name passes the address of its first element, i.e. by reference.

59.
★ Final term solved paper (vuattach 6)

break statement can be used outside a loop or switch statement.

  1. ATrue
  2. BFalse

break is only allowed inside a loop or switch.

60.
★ Final term solved paper (vuattach 6)

The keyword_______ is used to return some value from a function.

  1. Areturn
  2. Bbreak
  3. Ccontinue
  4. Dgoto

return sends a value back to the caller.

61.
★ Final term 2017 (paper 1)

Here the code is given below. You have to identify the problem in the code. while( (i < 10) && (i > 24))

  1. Athe logical operator && cannot be used in a test condition
  2. Bthe while loop is an exit-condition loop
  3. Cthe test condition is always true
  4. Dthe test condition is always false

No value can be both less than 10 and greater than 24, so the condition is always false.

62.
★ Final term 2017 (paper 1)

Which one of the statements given below is equivalent to sum += j*j ?

  1. Asum = j * j
  2. Bsum = sum + j
  3. Csum = sum + j * j
  4. Dsum * j = j

x += e means x = x + e, so sum += j*j is sum = sum + j*j.

63.
★ Final term 2017 (paper 1)

All elements of an array must be of ________.

  1. Adifferent data type
  2. Bfloat data types only
  3. Ccharacter data types only
  4. Dsame data type

An array is a collection of elements of one single data type.

64.
★ Final term 2017 (paper 1)

In C/C++, null character is represented as ________.

  1. A\n
  2. B\0
  3. C\t
  4. D\r

The null character that ends a C string is written '\0'; '\n' is newline.

65.
★ Final term 2017 (paper 1)

The address operator (&) is used with a ________.

  1. AStatement
  2. BExpression
  3. CVariable
  4. DConstant

& gives the memory address of a variable (an lvalue), not of a constant or expression.

66.
★ Final term 2017 (paper 1)

A variable declared inside a code block becomes the ________ variable for that block.

  1. Aglobal
  2. Bstatic
  3. Clocal
  4. Dinner

A variable declared inside a block has local scope limited to that block.

67.
★ Final term 2017 (paper 1)

A ________ name includes a primary name and an optional period with an extension.

  1. AFile
  2. BDisk
  3. CData
  4. DDatabase

A file name has a primary name and an optional extension after a period, e.g. data.txt.

68.
★ Final term 2017 (paper 1)

Individual characters in a string stored in an array can be accessed directly using array ________.

  1. ASuperscript
  2. BSubscript
  3. CScript
  4. DValue

Array elements, including characters of a string, are accessed with a subscript (index).

69.
★ Final term 2017 (paper 2)

Which of the following function call is "call by reference" for the following function prototype? void func (int *);

  1. Afunc(int &num);
  2. Bfunc(&num);
  3. Cfunc(*num);
  4. Dfunc(num);

Passing the address &num matches an int* parameter, so the function can change num.

70.
★ Final term 2017 (paper 2)

Which of the following is the correct way to initialize a character array 'course' with string 'programming'?

  1. Acourse[12] = "programming";
  2. Bcourse[] = ("programming");
  3. Ccourse[] = 'programming';
  4. Dcourse = "programming";

"programming" has 11 characters plus the null terminator, so 12 elements are needed; the other forms are invalid syntax.

71.
★ Final term 2017 (paper 2)

______ executes all the lines before error and stops at the line which contains the error.

  1. AInterpreter
  2. BCompiler
  3. CLinker
  4. DDebugger

An interpreter translates and runs one line at a time, so it stops at the first line with an error.

72.
★ Final term 2017 (paper 2)

Which of the following values are used in C/C++ to represent true and false?

  1. A1 and 0
  2. B1 and -1
  3. C11 and 00
  4. DAny numerical value

C/C++ uses 1 (non-zero) for true and 0 for false.

73.
★ Final term 2017 (paper 2)

What will be the output of this code segment? int arr[6] = {2, 3, 7, 4, 5, 6}; int *ptr1 = &arr[1]; int *ptr2 = &arr[4]; cout << (ptr2-ptr1);

  1. A3
  2. B9
  3. C12
  4. D2

Subtracting pointers gives the number of elements between them: 4 - 1 = 3.

74.
★ Final term 2017 (paper 2)

In case of ______ default mechanism of function calling is call by value.

  1. AVariable
  2. BArray
  3. CHeap
  4. DList

Ordinary variables are passed by value by default, while arrays are passed by reference.

75.
★ Final term 2017 (paper 3)

In Flow Chart, flow of control is represented by ____.

  1. ARectangle
  2. BCircle
  3. CDiamond
  4. DArrow

Arrows (flow lines) show the direction in which control moves between flowchart symbols.

76.
★ Final term 2017 (paper 3)

The operators ++ and -- are used to increment or decrement the value of a variable by ____.

  1. A3
  2. B2
  3. C1
  4. D4

Increment and decrement operators change the value by exactly 1.

77.
★ Final term 2017 (paper 3)

To assign a value to a character type variable, ____ are used around the value.

  1. Aparenthesis ( )
  2. Bsingle quotes ' '
  3. Cdouble quotes " "
  4. Dcurly braces { }

A char literal is written inside single quotes, e.g. 'a'.

78.
★ Final term 2017 (paper 3)

Let ptr1 and ptr2 are pointer variables that point to integer data types, then which one of the following arithmetic is allowed?

  1. Aptr1 + ptr2
  2. Bptr1 - ptr2
  3. Cptr1 * ptr2
  4. Dptr1 / ptr2

Subtracting two pointers into the same array gives the number of elements between them; adding, multiplying or dividing pointers is not allowed.

79.
★ Final term 2017 (paper 3)

When a call to a user-defined function finishes, the variable defined inside the function will ____.

  1. Astill in existence
  2. Bnot exist further
  3. Cfinish but a copy will remain in memory
  4. Dbecome static for other functions

Ordinary local (automatic) variables are destroyed when the function returns.

80.
★ Final term 2017 (paper 4)

You can use a ________ statement to transfer control elsewhere out of the nested structure.

  1. Acontinue
  2. Bgoto
  3. Cpause
  4. Dbreak

break leaves only the innermost loop/switch; goto can jump out of several nested structures at once.

81.
★ Final term 2017 (paper 4)

Which of the given operators is not a valid compound assignment operator?

  1. A>>=
  2. B=>>
  3. C*=
  4. D&=

=>> is not a C++ operator; >>=, *= and &= are compound assignment operators.

82.
★ Final term 2017 (paper 4)

Assignment operator is used for ___________.

  1. Acalculation
  2. Breading
  3. Cassigning values to variables
  4. Dequality checking

= stores the value on its right into the variable on its left; == checks equality.

83.
★ Final term 2017 (paper 4)

Missing semicolon ';' at the end of C++ statement causes a ___________ error.

  1. ALogical
  2. BSyntax
  3. CRuntime
  4. DCompile time

A missing semicolon breaks the language grammar, so the compiler reports a syntax error.

84.
★ Final term 2017 (paper 4)

Which of the following is not an example of int data type?

  1. A0
  2. B-32
  3. C65531
  4. D-4.0

-4.0 has a decimal point, so it is a floating-point (double) literal, not an int.

85.
★ Final term 2017 (paper 4)

For which array, the size of the array should be one more than the number of elements in an array?

  1. Aint
  2. Bdouble
  3. Cfloat
  4. Dchar

A char array holding a string needs one extra element for the terminating null character '\0'.

86.
★ Final term solved MCQs (Moaaz & Asad)

A Pointer is a special variable that contain

  1. AData values
  2. BMemory Address
  3. CBoth data and values
  4. DNone of the given option

A pointer holds the memory address of another variable.

87.
★ Final term solved MCQs (Moaaz & Asad)

Computer can understand only machine language code.

  1. ATrue
  2. BFalse

The processor executes only machine code; other code must be translated.

88.
★ Final term solved MCQs (Moaaz & Asad)

What will be the value of 'a' and 'b' after executing the following statements? a = 3; b = a++;

  1. A3, 4
  2. B4, 4
  3. C3, 3
  4. D4, 3

Post-increment gives b the old value 3, then a becomes 4.

89.
★ Final term solved MCQs (Moaaz & Asad)

Consider the following code segment. What will be the output of following code? int addValue (int *a){ int b = (*a) + 2; return b ; } main () { int x =6 ; cout << x << "," ; cout << addValue(&x) << "," ; cout << x ; }

  1. A6,8,6
  2. B6,6,8
  3. C6,8,8
  4. D6,6,6

addValue returns 8 without modifying x, so x prints 6 before and after.

90.
★ Final term solved MCQs (Moaaz & Asad)

_______ is used to trace the logic of the program and correct the logical errors.

  1. ACompiler
  2. BEditor
  3. CLinker
  4. DDebugger

A debugger lets you step through code to find logical errors.

91.
★ Final term solved MCQs (Moaaz & Asad)

Assignment operator is -------------------------associative.

  1. Aright
  2. Bleft
  3. Cbinary
  4. Dunary

a = b = c is evaluated as a = (b = c), so assignment is right-associative.

92.
★ Final term solved MCQs (Moaaz & Asad)

Header file: fstream.h includes the definition of the stream classes __________.

  1. Aifstream, fstream, cout
  2. Bifstream, fstream, ofstream
  3. Cfstream, cin, cout
  4. DNone of the above

fstream defines the file stream classes ifstream, ofstream and fstream.

93.
★ Final term solved MCQs (Moaaz & Asad)

Which of the following is correct way to initialize a variable x of int type with value 10?

  1. Aint x ; x = 10;
  2. Bint x = 10;
  3. Cint x, x = 10;
  4. Dx = 10;

Initialization gives the value in the declaration itself; option a declares then assigns.

94.
★ Final term solved MCQs (Moaaz & Asad)

Consider the following code segment. What will be the output of the following program? int func(int) ; int num = 10 ; int main(){ int num ; num = 5 ; cout << num ; cout << func(num) ; } int func(int x){ return num ; }

  1. A5, 5
  2. B10, 5
  3. C5, 10
  4. D10, 10

main prints its local num 5; func returns the global num 10.

95.
★ Final term solved MCQs (Moaaz & Asad)

What will be the correct syntax to declare two-dimensional array of float data type?

  1. Afloat arr{2}{2} ;
  2. Bfloat arr[2][2] ;
  3. Cfloat arr[2,2] ;
  4. Dfloat[2][2] arr ;

Each dimension of a C++ array gets its own pair of square brackets after the name.

96.
★ Final term solved MCQs (Moaaz & Asad)

The number 544.53 must be stored in _____ data type.

  1. Aint
  2. Bshort
  3. Cfloat
  4. Dchar

A value with a fractional part needs a floating-point type.

97.
★ Final term solved MCQs (Moaaz & Asad)

For which values of the integer_value will the following code becomes an infinite loop? int number=1; while (true) { cout << number; if (number == 3) break; number += integer_value; }

  1. Aany number other than 1 or 2
  2. Bonly 0
  3. Conly 1
  4. Donly 2

Starting at 1, number reaches exactly 3 only with step 1 or 2; any other step skips 3 and never breaks.

98.
★ Final term solved MCQs (Moaaz & Asad)

*.doc is _____________ by type.

  1. ASequential File
  2. BRandom Access File
  3. CData File
  4. DRecord File

A word-processor document is read and written at arbitrary positions, so it is a random access file.

99.
★ Final term solved MCQs (Moaaz & Asad)

C++ is a case-sensitive language

  1. ATrue
  2. BFalse

C++ treats Sum and sum as different identifiers.

100.
★ Final term solved MCQs (Moaaz & Asad)

What will be the correct syntax to assign an array named arr of 5 elements to a pointer ptr?

  1. A*ptr = arr ;
  2. Bptr = arr ;
  3. C*ptr = arr[5] ;
  4. Dptr = arr[5] ;

An array name converts to the address of its first element, which is assigned directly to ptr.

101.
★ Final term solved MCQs (Moaaz & Asad)

What will be the correct syntax to access the value of fourth element of an array using pointer ptr?

  1. Aptr[3]
  2. B(ptr+3)
  3. C*(ptr+3)
  4. DBoth 1and 3

ptr[3] and *(ptr+3) both read the element at index 3.

102.
★ Final term solved MCQs (Moaaz & Asad)

If it is required to copy an array to another array then,

  1. ABoth arrays must be of the same size and data type
  2. BBoth arrays may be of different size
  3. CBoth arrays may be of different data type
  4. DBoth arrays may be of different size and type

Element-by-element copying expects arrays of the same type and size.

103.
★ Final term solved MCQs (Moaaz & Asad)

If there is more than one statement in the block of a for loop, which of the following must be placed at the beginning and the ending of the loop block?

  1. Aparentheses ( )
  2. Bbraces { }
  3. Cbrackets [ ]
  4. Darrows < >

A compound statement (block) is enclosed in braces.

104.
★ Final term solved MCQs (Moaaz & Asad)

The operator used for casting, in C, is standard ________ operator.

  1. Anone of the given options.
  2. Bcast
  3. Ccost
  4. Dconst

C uses the cast operator (type) to convert values.

105.
★ Final term solved MCQs (Moaaz & Asad)

A pointer variable can be,

  1. ADecremented
  2. BIncremented
  3. CMultiplied
  4. DBoth Incremented and Decremented

Pointer arithmetic allows increment and decrement but not multiplication.

106.
★ Final term solved MCQs (Moaaz & Asad)

NULL value has been defined in ______ and _________ header files.

  1. Astrings.h and iostream.h
  2. Bctype.h and conio.c
  3. Cconio.c and conio.h
  4. Dstdlib.h and stddef.h

NULL is defined in stddef.h and also made available by stdlib.h.

107.
★ Final term solved MCQs (Moaaz & Asad)

When an array is passed to a function then default way of passing this array is,

  1. ABy data
  2. BBy reference
  3. CBy value
  4. DBy data type

An array name passes the address of its first element, so the function works on the original array.

108.
★ Final term solved MCQs (Moaaz & Asad)

Default mechanism of function calling in case of array is _____ and in case of variable is ___.

  1. ACall by value, call by reference
  2. BCall by reference, call by reference
  3. CCall by reference, call by value
  4. DCall by value, call by value

Arrays are passed by their address while ordinary variables are copied.

109.
★ Final term solved MCQs (Moaaz & Asad)

The programs, in which we allocate static memory, run essentially on ________

  1. AHeap
  2. BSystem Cache
  3. CNone of the given options
  4. DStack

Statically sized local data is placed on the stack, not the heap.

110.
★ Final term solved MCQs (Moaaz & Asad)

&& is -------------------- operator.

  1. AAn arithmetic
  2. BLogical
  3. CRelational
  4. DUnary

&& is the logical AND operator.

111.
★ Final term solved MCQs (Moaaz & Asad)

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

  1. Aisdigit(int c)
  2. Bisxdigit(int c )
  3. Ctolower(int c)
  4. DAll of the above

isdigit, isxdigit and tolower are all character-handling functions in ctype.h.

112.
★ Final term solved MCQs (Moaaz & Asad)

Which character is inserted at the end of string to indicate the end of string?

  1. Anew line
  2. Btab
  3. Cnull
  4. Dcarriage return

C strings end with the null character '\0'.

113.
★ Final term solved MCQs (Moaaz & Asad)

The object _______________may be used both for file input and file output

  1. Afstream,
  2. Bifstream,
  3. Cofstream,
  4. Dnone of the given options.

fstream supports both reading and writing.

114.
★ Final term solved MCQs (Moaaz & Asad)

The functions used for dynamic memory allocation return pointer of type ______

  1. Aint
  2. Bfloat
  3. Cvoid
  4. Ddouble

malloc, calloc and realloc return void*.

115.
★ Final term solved MCQs (Moaaz & Asad)

seekg() and write() are functionally _________________ .

  1. ADifferent
  2. BIdentical
  3. CTwo names of same function
  4. DNone of the above

seekg moves the get position while write outputs bytes.

116.
★ Final term solved MCQs (Moaaz & Asad)

When a pointer is incremented, it actually jumps the number of memory addresses

  1. AAccording to data type
  2. B1 byte exactly
  3. C1 bit exactly
  4. DA pointer variable can not be incremented

Incrementing a pointer advances it by the size of its pointed-to type.

117.
★ Final term solved MCQs (Moaaz & Asad)

The name of an array represents address of first location of array element.

  1. ATrue
  2. BFalse

An array name decays to a pointer to its first element.

118.
★ Final term solved MCQs (Moaaz & Asad)

If Num is an integer variable then Num++ means,

  1. AAdd 1 two times with Num
  2. BAdd 1 with Num
  3. CAdd 2 with Num
  4. DSubtract 2 from Num

++ increments the variable by 1.

119.
★ Final term solved MCQs (Moaaz & Asad)

Which looping process checks the test condition at the end of the loop?

  1. Afor
  2. Bwhile
  3. Cdo while
  4. Dno looping process checks the test condition at the end

do-while tests its condition after executing the body.

120.
★ Final term solved MCQs (Moaaz & Asad)

In a group of nested loops, which loop is executed the most number of times?

  1. Athe outermost loop
  2. Bthe innermost loop
  3. Call loops are executed the same number of times
  4. Dcannot be determined without knowing the size of the loops

The innermost loop runs fully for each iteration of the outer loops.

121.
★ Final term solved MCQs (Moaaz & Asad)

Consider the following statements to initialize a two-dimensional array. (i) int arr[2][3] = {4, 8, 9, 2, 1, 6} ; (ii) int arr[3][2] = {4, 8, 9, 2, 1, 6} ; (iii) int arr[][2] = {{4,8},{9, 2},{1, 6}} ; Which of the following option(s) are correct to initialize a two-dimensional array with 3 rows and 2 columns?

  1. A(ii) only
  2. B(iii) only
  3. C(ii) and (iii)
  4. D(i) and (iii)

Both (ii) and (iii) give 3 rows of 2 columns; (i) has 2 rows of 3.

122.
★ Solved MCQs collection

While developing a program, should we think about the user interface?

  1. AYes
  2. BNo

A good program design considers how users will interact with it.

123.
★ Solved MCQs collection

A character is stored in the memory in _________

  1. Abyte
  2. Binteger
  3. Cstring
  4. DNone of the given

A char occupies one byte of memory.

124.
★ Solved MCQs collection

When the logical operator OR (||) combines two expressions exp1 and exp2, then the result will be false only,

  1. AWhen both exp1 and exp2 are true
  2. BWhen both exp1 and exp2 are false
  3. CWhen exp1 is true and exp2 is false
  4. DWhen exp1 is false and exp2 is true

|| yields false only when both operands are false.

125.
★ Solved MCQs collection

Suppose we have int y[10]; To access the 4th element of the array we write_________

  1. Ay[4];
  2. By[3];
  3. Cy[2];
  4. Dnone of given

Indexing starts at 0, so the 4th element is y[3].

126.
★ Solved MCQs collection

ofstream is used for________

  1. AInput file stream
  2. BOutput file stream
  3. CInput and output file stream
  4. DAll of the given

ofstream is the output file stream class.

127.
★ Solved MCQs collection

In C/C++ the string constant is enclosed

  1. AIn curly braces
  2. BIn small braces
  3. CIn single quotes
  4. DIn double quotes

String literals are written inside double quotes.

128.
★ Solved MCQs collection

In flow chart process is represented by

  1. ARectangle
  2. BArrow symbol
  3. COval
  4. DCircle

A rectangle denotes a process step in a flowchart.

129.
★ Solved MCQs collection

When we are using const keyword with a variable x then initializing it at the time of declaration is,

  1. AMust
  2. BOptional
  3. CNot necessary
  4. DA syntax error

A const variable cannot be assigned later, so it must be initialized when declared.

130.
★ Solved MCQs collection

Which of the following is the correct way to assign an integer value 5 to element of a matrix say 'm' at second row and third column?

  1. Am[2][3] = 5 ;
  2. Bm[3][2] = 5 ;
  3. Cm[1][2] = 5 ;
  4. Dm[2][3] = '5';

With zero-based indexing, second row is index 1 and third column is index 2.

131.
★ Solved MCQs collection

How many total elements must be in two-dimensional array of 3 rows and 2 columns?

  1. A4
  2. B5
  3. C6
  4. D7

3 rows x 2 columns = 6 elements.

132.
★ Solved MCQs collection

Which of the following is the correct statement for the following declaration? const int *ptr;

  1. Aptr is a constant pointer
  2. Bptr is constant integer pointer
  3. Cptr is a constant pointer to int
  4. Dptr is a pointer to const int

The const applies to the pointed-to int, not to the pointer.

133.
★ Solved MCQs collection

Consider the following code segment. What will be the output of this code segment? int arr[6] = {2, 3, 7, 4, 5, 6} ; int *ptr1 = &arr[1] ; int *ptr2 = &arr[4] ; cout << (ptr2-ptr1) ;

  1. A3
  2. B9
  3. C12
  4. D2

Pointer subtraction gives the element distance 4 - 1 = 3, not the difference of values.

134.
★ Solved MCQs collection

C is a/an ______ language

  1. Alow level
  2. Bobject based
  3. Cobject oriented
  4. Dfunction oriented

C is a procedural language built around functions, not objects.

135.
★ Solved MCQs collection

The variables having a name, type and size are just like empty boxes.

  1. AFalse
  2. BTrue

A declared variable is like a labelled box that can hold a value of its type.

136.
★ Solved MCQs collection

What's wrong with this for loop? for (int k = 2, k <=12, k++)

  1. Athe increment should always be ++k
  2. Bthe variable must always be the letter i when using a for loop
  3. Cthere should be a semicolon at the end of the statement
  4. Dthe commas should be semicolons

The three parts of a for header are separated by semicolons.

137.
★ Solved MCQs collection

Syntax of union is identical to ______

  1. AStructure
  2. BClass
  3. CFunction
  4. DNone of the given options

A union is declared with the same syntax as a struct.

138.
★ Solved MCQs collection

If we do not mention any return_value_type with a function, it will return an _____ value.

  1. Aint
  2. Bvoid
  3. Cdouble
  4. Dfloat

In old C/C++ the omitted return type defaults to int.

139.
★ Solved MCQs collection

Let suppose int a, b, c, d, e; a = b = c = d = e = 42; This can be interpreted by the compiler as:

  1. Aa = (b = (c = (d = (e = 42))));
  2. B(a = b = (c = (d = (e = 42))));
  3. Ca = b = (c = (d = (e = 42)));
  4. D(a = b) = (c = d) = (e = 42);

Assignment is right-associative, so it groups from the right.

140.
★ Solved MCQs collection

Missing semicolon ';' at the end of C++ statement is

  1. ALogical error
  2. BSyntax error
  3. CRuntime error
  4. DNone of the given options

The compiler rejects a statement without its terminating semicolon.

141.
★ Solved MCQs collection

An array stores the numbers into consecutive memory locations.

  1. ATrue
  2. BFalse

Array elements are stored contiguously.

142.
★ Solved MCQs collection

A variable which is defined inside a function is called

  1. AAutomatic variable
  2. BGlobal variable
  3. CFunctional variable
  4. DNone of the given option

Local variables are automatic by default.

143.
★ Solved MCQs collection

The code is written to __________ the program.

  1. Aimplement
  2. Bdesign
  3. Canalysis
  4. Dnone of the given options.

Writing code is the implementation stage.

144.
★ Solved MCQs collection

Analysis is the -------------- step in designing a program.

  1. ALast
  2. BMiddle
  3. CPost Design
  4. DFirst

Analysis of the problem comes first.

145.
★ Midterm Spring 2009

In flow chart, the symbol used for decision making is,

  1. ARectangle
  2. BCircle
  3. CArrow
  4. DDiamond

A diamond represents a decision in a flowchart.

146.
★ Midterm Spring 2009

The correct syntax of do-while loop is,

  1. A(condition ) while; do { statements; };
  2. B{ statements; } do-while ();
  3. Cwhile(condition); do { statements; };
  4. Ddo { statements; } while (condition);

do-while puts the body first and ends with while (condition);

147.
★ Midterm Spring 2009

C++ views each file as a sequential stream of ________________ .

  1. ABytes
  2. BBits
  3. C0’s or 1’s
  4. DWords

A file is treated as a sequence of bytes.

148.
★ Midterm Spring 2009

If the elements of an array are already sorted then the useful search algorithm is,

  1. ALinear search
  2. BBinary search
  3. CQuick search
  4. DRandom search

Binary search needs sorted data and halves the range each step.

149.
★ Midterm Spring 2009

Each pass through a loop is called a/an

  1. Aenumeration
  2. Biteration
  3. Cculmination
  4. Dpass through

One execution of a loop body is an iteration.

150.
★ Midterm Spring 2009

Call by reference mechanism should be used in a program when there is i. large amount of data to be passed ii. small amount of data to be passed iii. need to change the passed data iv. no need to change the passed data Choose the appropriate option for the above case.

  1. A(i) and (ii) only
  2. B(i) and (iii) only
  3. C(ii) and (iii) only
  4. D(ii) and (iv) only

Reference avoids copying large data and lets the function change the caller's data.

151.
★ Midterm Spring 2009

Which of the following is the starting index of an array in C++?

  1. A0
  2. B1
  3. C-1
  4. Dany number

C++ arrays are zero-indexed.

152.
★ Midterm Spring 2009

Which of the following is an extension of header file?

  1. A.exe
  2. B.txt
  3. C.h
  4. D.c

Header files conventionally use the .h extension.

153.
★ Midterm Spring 2009

We want to access array in random order which approach is better?

  1. APointers
  2. BArray index
  3. CBoth pointers and array index are better
  4. DNone of the given options.

Indexing is better for random access; pointers suit sequential access, per the handouts.

154.
★ Midterm Spring 2009

When we declare a multidimensional array the compiler stores the elements of multidimensional array in the form of,

  1. AColumns
  2. BRows
  3. CContiguous memory location
  4. DMatrix

All elements are laid out in one contiguous block (row-major).

155.
★ Past paper collection

We can ___________ pointer.

  1. Aincrement
  2. Bdecrement
  3. Creassign
  4. Dall of the given

A non-const pointer can be incremented, decremented and made to point elsewhere.

156.
★ Past paper collection

char **argv can be read as__________________.

  1. Apointer to pointer
  2. Bpointer to char
  3. Cpointer to pointer to char
  4. DNone of the given

Read right to left: argv is a pointer to a pointer to char.

157.
★ Past paper collection

To read command-line arguments, the main() function itself must be given ___________ arguments.

  1. A1
  2. B2
  3. C3
  4. D4

main(int argc, char **argv) takes two arguments.

158.
★ Past paper collection

The increment of a pointer depends on its___________.

  1. Avariable
  2. Bvalue
  3. Cdata type
  4. DNone of the given

Pointer arithmetic moves by the size of the pointed-to type.

159.
★ Past paper collection

Transpose of a matrix means that when we interchange rows and columns___________.

  1. Athe first row becomes the Last column
  2. Bthe first row becomes the first column
  3. Cthe Last row becomes the first column
  4. Dthe first column becomes the first row

In a transpose, row i becomes column i, so the first row becomes the first column.

160.
★ Past paper collection

We can define a matrix as__________ array.

  1. ASorted
  2. BUnsorted
  3. CSingle dimensional
  4. DMulti dimensional

A matrix has rows and columns, so it is stored as a two-dimensional array.

161.
★ Past paper collection

A ________is an array of characters that can store number of character specified.

  1. AChar
  2. BString
  3. CMultidimensional array
  4. DData type

A C-style string is a char array of a fixed size.

162.
★ Past paper collection

Given a two dimensional array of integers, what would be the correct way of assigning the value 6 to the element at third row and fourth column?

  1. Aarray[3][4] = 6 ;
  2. Barray[2][4] = 6 ;
  3. Carray[4][3] = 6 ;
  4. Darray[2][3] = 6 ;

Indexes start at 0, so third row is 2 and fourth column is 3.

163.
★ Past paper collection

________ of a variable means the locations within a program from where it can be accessed.

  1. AData type
  2. BVisibility
  3. CValue
  4. DReference

Visibility (scope) is where in the program a variable can be used.

164.
★ Past paper collection

Which of the following function call is "call by reference" for the following function prototype? int add (int *);

  1. Aadd(&x);
  2. Badd(int x);
  3. Cadd(x);
  4. Dadd(*x);

A pointer parameter needs the address of the variable, &x.

165.
★ Past paper collection

Which of the function call is call by value for the following function prototype? float add(float);

  1. Aadd(&x);
  2. Badd(x);
  3. Cadd(float x);
  4. Dadd(*x);

Passing the variable name sends a copy of its value.

166.
★ Past paper collection

______ will be used for enclosing function statements into a block.

  1. A" "
  2. B()
  3. C[]
  4. D{}

Curly braces mark the start and end of a block.

167.
★ Past paper collection

When the break statement is encountered in a loop's body, it transfers the control ________ from the current loop.

  1. AInside
  2. BOutside
  3. CTo break statement
  4. DTo continue statement

break exits the loop and continues after it.

168.
★ Past paper collection

What will be the output of following code segment? for (int i = 2; i<10; i++){ if ( i == 5) continue; cout << i << "," ; }

  1. A2,3,7,8,9
  2. B2,3,4,6,7,8,9
  3. C2,3,4
  4. D4,6,7,8,9

continue skips printing only when i is 5; the loop runs 2 to 9.

169.
★ Past paper collection

What will be the result of the expression k = ++m; if initially k = 0 and m = 5?

  1. A0
  2. B5
  3. C6
  4. D4

Pre-increment makes m 6 first, then assigns 6 to k.

170.
★ Past paper collection

How many times the following do-while loop will execute? int k = 10; do { cout << "Statements" << endl; k -= 2; } while(k>0);

  1. A4
  2. B5
  3. C6
  4. D7

The body runs for k = 10, 8, 6, 4, 2; then k is 0 and the loop stops: 5 times.

171.
★ Past paper collection

Which of the following loops checks the test condition at the end of the loop?

  1. AWhile
  2. BDo-While
  3. CFor
  4. DNested Loop

do-while tests its condition after the body, so it runs at least once.

172.
★ Past paper collection

How many times the following loop will execute? int j = 3; while(j > 0) { cout << "Statements" << endl; j -= 2; }

  1. A0
  2. B1
  3. C2
  4. D3

The body runs for j = 3 and j = 1; then j is -1 and the loop ends.

173.
★ Past paper collection

!( x > 3) means in C++ that

  1. Ax is greater than 3
  2. Bx is less than or equal to 3
  3. Cx is less than 3
  4. Dx is equal to 3

Not (x > 3) is the same as x <= 3.

174.
★ Past paper collection

When the logical operator && combines two expressions then the result will be true only when the both expressions are ____________

  1. ALogical
  2. BArithmetic
  3. Ctrue
  4. Dfalse

&& is true only when both operands are true.

175.
★ Past paper collection

< and > both are _________ operators.

  1. AArithmetic
  2. BRelational
  3. CLogical
  4. DMathematical

< and > compare two values, so they are relational operators.

176.
★ Past paper collection

!( x < 3) means in C++ that

  1. Ax is less than 3
  2. Bx is greater than or equal to 3
  3. Cx is greater than 3
  4. Dx is equal to 3

Not (x < 3) is the same as x >= 3.

177.
★ Past paper collection

!= operator is used to check whether the operand on the left-hand-side is __________ to the operand on the right-hand-side.

  1. ALess than or equal
  2. BGreater than or equal
  3. CNot equal
  4. DApproximately equal to

!= tests whether two values are not equal.

178.
★ Past paper collection

The most suitable data type for number 325.25 is ______.

  1. Achar
  2. Bint
  3. Cshort
  4. Dfloat

A number with a fractional part needs a floating-point type.

179.
★ Past paper collection

Which of the following will be the most appropriate data type to store the value 63.547?

  1. AInteger
  2. BCharacter
  3. CShort
  4. DFloat

A decimal value is stored in a floating-point type.

180.
★ Past paper collection

____________ operators are the ones that require two operands on both sides of the operator.

  1. ADouble
  2. BTow sided
  3. CBinary
  4. DNone of the given

Binary operators take two operands.

181.
★ Past paper collection

It is the job of __________ to transfer the executable code from hard disk to main memory.

  1. AInterpreter
  2. BDebugger
  3. CLinker
  4. DLoader

The loader copies the executable program into memory to run it.

182.
★ Past paper collection

_________ will explain the function of a program.

  1. AComments
  2. BDebugger
  3. CCompiler
  4. DLinker

Comments describe what the code does for human readers.

183.
★ Final term Fall 2005

If we open a file stream myfile for reading, what will give us the current position of the file pointer?

  1. Atellg()
  2. Btellp()
  3. Cseekg()
  4. Dseekp()

tellg() returns the current get (read) position of an input stream.

184.
★ Final term Spring 2005

Which one of the following operators is a unary operator?

  1. AOR ( || )
  2. BAND ( &&)
  3. CXOR ( ^ )
  4. DComplement operator ( ~ )

~ works on a single operand; ||, && and ^ need two.