CS201 – Introduction to Programming: Midterm Important MCQs (436 Solved Questions)
Computer Science • Read every solved MCQ with its verified answer key directly on this page. Free, no login required.
All 664 Midterm Packs · CS201 Course Page · CS201 Subjective Pack (36 Q&As)
-
There are mainly ________ types of software.
Topic: Programming Basics & Program Design (29 MCQs)
- Two ✓ Correct answer
- Three
- Four
- Five
-
In C/C++, the #include is called:
Topic: Programming Basics & Program Design (29 MCQs)
- Header file
- Preprocessor directive ✓ Correct answer
- Statement
- Function
-
A precise sequence of steps to solve a problem is called:
Topic: Programming Basics & Program Design (29 MCQs)
- Statement
- Program ✓ Correct answer
- Utility
- Routine
-
Analysis is the ________ step in designing a program.
Topic: Programming Basics & Program Design (29 MCQs)
- Last
- Middle
- Post Design
- First ✓ Correct answer
-
In ________, we try to have a precise problem statement.
Topic: Programming Basics & Program Design (29 MCQs)
- Design
- Analysis ✓ Correct answer
- Coding
- Testing
-
At the design phase, we try to break up the problem into ________.
Topic: Programming Basics & Program Design (29 MCQs)
- Functional units ✓ Correct answer
- Variables
- Loops
- Files
-
For breaking a complex problem into smaller pieces, we use ________.
Topic: Programming Basics & Program Design (29 MCQs)
- Loops
- Functions ✓ Correct answer
- Arrays
- Pointers
-
In a flow chart, the symbol used for decision making is:
Topic: Programming Basics & Program Design (29 MCQs)
- Rectangle
- Circle
- Arrow
- Diamond ✓ Correct answer
-
In a flow chart, a process is represented by:
Topic: Programming Basics & Program Design (29 MCQs)
- Rectangle ✓ Correct answer
- Arrow symbol
- Oval
- Circle
-
Paying attention to detail in designing a program is ________.
Topic: Programming Basics & Program Design (29 MCQs)
- Time consuming
- Redundant
- Necessary ✓ Correct answer
- Somewhat good
-
While programming, it is good to provide an easy to understand and easy to use interface; this programming skill is called ________.
Topic: Programming Basics & Program Design (29 MCQs)
- Scalability
- Usability ✓ Correct answer
- Reliability
- Sustainability
-
Commenting the code ________.
Topic: Programming Basics & Program Design (29 MCQs)
- Makes a program easy to understand for others ✓ Correct answer
- Makes programs heavy, i.e. more space is needed for executable
- Makes it difficult to compile
- All of the given options
-
Word processor is a type of:
Topic: Programming Basics & Program Design (29 MCQs)
- Operating system
- Application software ✓ Correct answer
- Device driver
- Utility software
-
C is widely known as the development language of the ________ operating system.
Topic: Programming Basics & Program Design (29 MCQs)
- Windows
- Unix ✓ Correct answer
- Mac OS
- Linux
-
The compiler of the C language is written in:
Topic: Programming Basics & Program Design (29 MCQs)
- Java language
- UNIX
- FORTRAN language
- C language ✓ Correct answer
-
C is a/an ________ language.
Topic: Programming Basics & Program Design (29 MCQs)
- Low level
- Object based
- Object oriented
- Function oriented ✓ Correct answer
-
C++ is a ________ language.
Topic: Programming Basics & Program Design (29 MCQs)
- High level ✓ Correct answer
- Low level
- Assembly
- Machine
-
A compiler translates a high level language program into ________ language code.
Topic: Programming Basics & Program Design (29 MCQs)
- Assembly
- Machine ✓ Correct answer
- Source
- Object-oriented
-
Which of the following is an extension of a header file?
Topic: Programming Basics & Program Design (29 MCQs)
- .exe
- .txt
- .h ✓ Correct answer
- .c
-
If you create a header file of your own and save it in the current working directory, then you must enclose your header file within ________.
Topic: Programming Basics & Program Design (29 MCQs)
- Angle brackets < >
- Quotation marks ✓ Correct answer
- Square brackets [ ]
- Parentheses ( )
-
For console input and output we use the ________ header file.
Topic: Programming Basics & Program Design (29 MCQs)
- conio.h ✓ Correct answer
- iostream.h
- fstream.h
- stdlib.h
-
We should not use variable names that are starting with ________, because in C++ there are lots of internal constants and symbolic names that start with it.
Topic: Programming Basics & Program Design (29 MCQs)
- A capital letter
- Double underscore ✓ Correct answer
- A digit
- The dollar sign
-
Which of the following cannot be a variable name?
Topic: Programming Basics & Program Design (29 MCQs)
- area
- _area
- 10area ✓ Correct answer
- area2
-
What is the other name of a variable?
Topic: Programming Basics & Program Design (29 MCQs)
- Constant
- Identifier ✓ Correct answer
- Operator
- Keyword
-
Which of the following is NOT a reserved word in C/C++?
Topic: Programming Basics & Program Design (29 MCQs)
- int
- float
- double
- sum ✓ Correct answer
-
The variables having a name, type and size are just like empty boxes.
Topic: Programming Basics & Program Design (29 MCQs)
- True ✓ Correct answer
- False
-
Initialization of a variable at the time of definition is:
Topic: Programming Basics & Program Design (29 MCQs)
- Must
- Necessary
- Good programming ✓ Correct answer
- None of the given options
-
When we are using the const keyword with a variable x, then initializing it at the time of declaration is:
Topic: Programming Basics & Program Design (29 MCQs)
- Must ✓ Correct answer
- Optional
- Not necessary
- A syntax error
-
If a function has not been declared before it is used, it is a ________.
Topic: Programming Basics & Program Design (29 MCQs)
- Logical error
- Syntax error ✓ Correct answer
- Run-time error
- Linker warning only
-
The size of the int data type is:
Topic: Data Types, Variables & Operators (21 MCQs)
- 1 byte
- 2 bytes
- 3 bytes
- 4 bytes ✓ Correct answer
-
&& is a ________ operator.
Topic: Data Types, Variables & Operators (21 MCQs)
- Arithmetic
- Logical ✓ Correct answer
- Relational
- Unary
-
<, <=, >, >= are called ________ operators.
Topic: Data Types, Variables & Operators (21 MCQs)
- Arithmetic
- Logical
- Relational ✓ Correct answer
- Assignment
-
Which one of the following is used to perform the bit-wise OR operation?
Topic: Data Types, Variables & Operators (21 MCQs)
- ||
- | ✓ Correct answer
- &
- &&
-
When the logical operator AND (&&) combines two expressions exp1 and exp2, then the result will be true only ________.
Topic: Data Types, Variables & Operators (21 MCQs)
- When both exp1 and exp2 are true ✓ Correct answer
- When both exp1 and exp2 are false
- When exp1 is true and exp2 is false
- When exp1 is false and exp2 is true
-
The expression ((a + b) == 10) && ((x + y) == 20) is true only if ________.
Topic: Data Types, Variables & Operators (21 MCQs)
- Only (a + b) == 10 is true
- Only (x + y) == 20 is true
- Both ((a + b) == 10) and ((x + y) == 20) are true ✓ Correct answer
- Either of them is true
-
a = a + 1; can also be written as ________.
Topic: Data Types, Variables & Operators (21 MCQs)
- a += 1; ✓ Correct answer
- a =+ 1;
- a ++ 1;
- a = 1 +;
-
Which of the following is the correct way to write a compound assignment operator?
Topic: Data Types, Variables & Operators (21 MCQs)
- x =+ 4
- x += 4 ✓ Correct answer
- x + = 4
- x = +4
-
If y = 20 and z = y++, then the value of z will be ________.
Topic: Data Types, Variables & Operators (21 MCQs)
- 21
- 20 ✓ Correct answer
- 19
- 0
-
________ will return the number of bytes reserved for a variable or data type.
Topic: Data Types, Variables & Operators (21 MCQs)
- sizeof operator ✓ Correct answer
- malloc function
- typedef operator
- strlen function
-
Shifting the binary number is similar to shifting the ________ number.
Topic: Data Types, Variables & Operators (21 MCQs)
- Octal
- Decimal ✓ Correct answer
- Hexadecimal
- Roman
-
The address operator (&) can be used with a:
Topic: Data Types, Variables & Operators (21 MCQs)
- Statement
- Expression
- Variable ✓ Correct answer
- Constant
-
The ________ operator is used to pass the address of a variable in the call by reference method.
Topic: Data Types, Variables & Operators (21 MCQs)
- *
- & ✓ Correct answer
- &&
- ->
-
A reference to a variable can be obtained by preceding the identifier of the variable with the ________.
Topic: Data Types, Variables & Operators (21 MCQs)
- Asterisk sign *
- Ampersand sign & ✓ Correct answer
- Percent sign %
- Dollar sign $
-
In C/C++, the header file which is used to perform useful tasks and manipulation of character data is:
Topic: Data Types, Variables & Operators (21 MCQs)
- cplext.h
- ctype.h ✓ Correct answer
- stdio.h
- delay.h
-
Which of the following function(s) is/are included in the stdlib.h header file? 1. double atof(const char *nptr) 2. int atoi(const char *nptr) 3. char *strcpy(char *s1, const char *s2)
Topic: Data Types, Variables & Operators
- double atof(const char *nptr)
- int atoi(const char *nptr)
- char *strcpy(char *s1, const char *s2)
- 1 and 2 only ✓ Correct answer
-
Which of the following header files defines the rand() function?
Topic: Data Types, Variables & Operators (21 MCQs)
- iostream.h
- conio.h
- stdlib.h ✓ Correct answer
- stdio.h
-
To convert the value of one type into another type using built-in functions, we include the ________ header file.
Topic: Data Types, Variables & Operators (21 MCQs)
- conio.h
- stdlib.h ✓ Correct answer
- iostream.h
- string.h
-
________ returns true if c is a letter and false otherwise.
Topic: Data Types, Variables & Operators (21 MCQs)
- int isalpha(int c) ✓ Correct answer
- int isdigit(int c)
- int isalnum(int c)
- int isspace(int c)
-
________ returns true if c is a digit and false otherwise.
Topic: Data Types, Variables & Operators (21 MCQs)
- int isalpha(int c)
- int isdigit(int c) ✓ Correct answer
- int islower(int c)
- int isupper(int c)
-
The parameter passed to the isdigit() function is a/an ________ variable.
Topic: Data Types, Variables & Operators (21 MCQs)
- Integer ✓ Correct answer
- Character array
- Float
- String
-
In the if structure, the block of statements is executed only:
Topic: Decision Structures (if & switch) (5 MCQs)
- When the condition is false
- When it contains arithmetic operators
- When it contains logical operators
- When the condition is true ✓ Correct answer
-
The ________ structure is a multiple-selection construct which makes the code more efficient and easy to read and understand.
Topic: Decision Structures (if & switch) (5 MCQs)
- multiple-if
- switch ✓ Correct answer
- if-else
- else-if
-
The ________ statement allows us to select from multiple choices based on a set of fixed values for a given expression.
Topic: Decision Structures (if & switch) (5 MCQs)
- switch ✓ Correct answer
- break
- continue
- goto
-
The ________ statement is used to terminate the processing of a particular case and exit from the switch structure.
Topic: Decision Structures (if & switch) (5 MCQs)
- continue
- goto
- break ✓ Correct answer
- return
-
If the break statement is missed in a switch statement, then:
Topic: Decision Structures (if & switch) (5 MCQs)
- The compiler will give an error
- This may cause a logical error ✓ Correct answer
- There is no effect on the program
- The program stops its execution
-
The correct syntax of the do-while loop is:
Topic: Loops (11 MCQs)
- (condition) while; do { statements; };
- { statements; } do-while ();
- while (condition); do { statements; };
- do { statements; } while (condition); ✓ Correct answer
-
In a do-while loop, the condition is checked ________ one execution of the loop.
Topic: Loops (11 MCQs)
- Before
- After ✓ Correct answer
- During
- Never
-
Each pass through a loop is called a/an:
Topic: Loops (11 MCQs)
- Enumeration
- Iteration ✓ Correct answer
- Culmination
- Pass through
-
A continue statement causes execution to skip to:
Topic: Loops (11 MCQs)
- The return 0; statement
- The first statement after the loop
- The statements following the continue statement
- The next iteration of the loop ✓ Correct answer
-
The continue statement usually forces the immediate ________ iteration of the loop.
Topic: Loops (11 MCQs)
- Previous
- Next ✓ Correct answer
- Last
- First
-
Which looping process is best when the number of iterations is known?
Topic: Loops (11 MCQs)
- for ✓ Correct answer
- while
- do-while
- All looping processes require that the iterations be known
-
What's wrong with this for loop? for (int k = 2, k <= 12, k++)
Topic: Loops (11 MCQs)
- The increment should always be ++k
- The variable must always be the letter i when using a for loop
- There should be a semicolon at the end of the statement
- The commas should be semicolons ✓ Correct answer
-
The 'while' loop may execute ________ or more times.
Topic: Loops (11 MCQs)
- Three
- Zero ✓ Correct answer
- Two
- One
-
In the following nested for loop, which loop will run the most number of times? for (int i = 0; i < 5; i++) { for (int k = 0; k < 5; k++) { ............ } }
Topic: Loops (11 MCQs)
- Outer loop
- Inner loop ✓ Correct answer
- Both run an equal number of times
- None of the given options
-
What will be the output of the following code segment? for (int i = 2; i < 10; i++) { if (i == 5) continue; cout << i << ","; }
Topic: Loops (11 MCQs)
- 2,3,4,5,6,7,8,9
- 2,3,4,6,7,8,9 ✓ Correct answer
- 2,3,4,5,6,7,8
- 3,4,6,7,8,9
-
For which values of integer_value will the following code become an infinite loop? int number = 1; while (true) { cout << number; if (number == 3) break; number += integer_value; }
Topic: Loops (11 MCQs)
- Any number other than 1 or 2 ✓ Correct answer
- Only 0
- Only 1
- Only 2
-
The return type of a function that does not return any value must be ________.
Topic: Functions & References (10 MCQs)
- int
- void ✓ Correct answer
- double
- float
-
The call by reference mechanism should be used in a program when there is: (i) a large amount of data to be passed (ii) a small amount of data to be passed (iii) a need to change the passed data (iv) no need to change the passed data
Topic: Functions & References (10 MCQs)
- (i) and (ii) only
- (i) and (iii) only ✓ Correct answer
- (ii) and (iii) only
- (ii) and (iv) only
-
The keyword ________ is used to get some value back from a function.
Topic: Functions & References (10 MCQs)
- return ✓ Correct answer
- break
- continue
- goto
-
Identify the correct option which is used for calling the function: float area(int)
Topic: Functions & References (10 MCQs)
- area(&num);
- area(num); ✓ Correct answer
- area(int num);
- area(*num);
-
The function will return a reference to the global variable that exists throughout the program, and thus there will be no danger of ________.
Topic: Functions & References (10 MCQs)
- Memory leak
- Dangling reference ✓ Correct answer
- Infinite loop
- Stack overflow
-
To prevent a dangling reference, the function returning a reference should be used with ________.
Topic: Functions & References (10 MCQs)
- Local variables
- Static and global variables ✓ Correct answer
- Temporary variables
- Register variables
-
Reference variables must ________.
Topic: Functions & References (10 MCQs)
- Be initialized at the time of declaration ✓ Correct answer
- Be initialized after they are declared
- Never be initialized
- Be initialized at the end of the program
-
The difference between a pointer and a reference is that ________.
Topic: Functions & References (10 MCQs)
- We can do arithmetic with pointers ✓ Correct answer
- We can do arithmetic with references
- Both support arithmetic
- Neither supports arithmetic
-
How many parameter(s) does the function getline() take?
Topic: Functions & References (10 MCQs)
- 0
- 1
- 2 ✓ Correct answer
- 3
-
The function of cin is:
Topic: Functions & References (10 MCQs)
- To display a message
- To read data from the keyboard ✓ Correct answer
- To display output on the screen
- To send data to the printer
-
If the elements of an array are already sorted, then the useful search algorithm is:
Topic: Arrays & Strings (40 MCQs)
- Linear search
- Binary search ✓ Correct answer
- Quick search
- Random search
-
If there are 2^(n+1) elements in an array, then what would be the number of iterations required to search a number using the binary search algorithm?
Topic: Arrays & Strings (40 MCQs)
- n elements
- (n+1) elements ✓ Correct answer
- 2(n+1) elements
- (n-1) elements
-
Which of the following is the starting index of an array in C++?
Topic: Arrays & Strings (40 MCQs)
- 0 ✓ Correct answer
- 1
- -1
- Any number
-
If an array has 50 elements, what is the allowable range of subscripts?
Topic: Arrays & Strings (40 MCQs)
- 1-50
- 0-49 ✓ Correct answer
- 0-50
- 1-49
-
What is the highest legal index for the following array? int arr[4];
Topic: Arrays & Strings (40 MCQs)
- 4
- 3 ✓ Correct answer
- 2
- 1
-
In C++, what will be the highest index of the following array? int array[15];
Topic: Arrays & Strings (40 MCQs)
- 15
- 16
- 14 ✓ Correct answer
- 13
-
All elements of an array must be of ________ data type(s).
Topic: Arrays & Strings (40 MCQs)
- Different
- Same ✓ Correct answer
- Mixed
- Any
-
How do we declare an array of integer type whose size is 20 with the array name "count"?
Topic: Arrays & Strings (40 MCQs)
- int count[20]; ✓ Correct answer
- count int[20];
- int [20]count;
- array count[20];
-
What is the correct syntax to declare an array of size 10 of int data type?
Topic: Arrays & Strings (40 MCQs)
- int [10] name;
- name[10] int;
- int name[10]; ✓ Correct answer
- int name[];
-
Which one of the following is the correct syntax of an array declaration, where the array size is 5 and it is of float data type?
Topic: Arrays & Strings (40 MCQs)
- float name[5]; ✓ Correct answer
- int name[5];
- float [5]name;
- float name(5);
-
Following is the declaration of a ________ array. int arr[2][2][2];
Topic: Arrays & Strings (40 MCQs)
- 1-Dimensional
- 2-Dimensional
- 3-Dimensional ✓ Correct answer
- Multi-dimensional pointer
-
In a three-dimensional array, we use ________ for loop(s) to populate the array.
Topic: Arrays & Strings (40 MCQs)
- 1
- 2
- 3 ✓ Correct answer
- 4
-
To manipulate an n-dimensional array, ________ nested loops are required.
Topic: Arrays & Strings (40 MCQs)
- 2
- n ✓ Correct answer
- n+1
- n-1
-
When we declare a multidimensional array, the compiler stores the elements of the multidimensional array in the form of:
Topic: Arrays & Strings (40 MCQs)
- Columns
- Rows
- Contiguous memory locations ✓ Correct answer
- Matrix
-
We can define a matrix as a ________ array.
Topic: Arrays & Strings (40 MCQs)
- Single dimensional
- Two-dimensional ✓ Correct answer
- Three-dimensional
- Zero-dimensional
-
Transpose of a matrix means that when we interchange rows and columns, ________.
Topic: Arrays & Strings (40 MCQs)
- The first row becomes the first column ✓ Correct answer
- The first column becomes the last row
- The matrix is reversed
- The diagonal is changed
-
How many total elements must be there in a two-dimensional array of 3 rows and 2 columns?
Topic: Arrays & Strings (40 MCQs)
- 4
- 5
- 6 ✓ Correct answer
- 7
-
Which of the following is the correct way to assign an integer value 5 to an element of a matrix 'm' at the second row and third column?
Topic: Arrays & Strings (40 MCQs)
- m[2][3] = 5;
- m[3][2] = 5;
- m[1][2] = 5; ✓ Correct answer
- m[2][3] = '5';
-
Given a two-dimensional array of integers, what would be the correct way of assigning the value 6 to the element at the third row and fourth column?
Topic: Arrays & Strings (40 MCQs)
- array[3][4] = 6;
- array[2][3] = 6; ✓ Correct answer
- array[4][3] = 6;
- array[3][3] = 6;
-
Suppose we have int y[10]; To access the 4th element of the array we write:
Topic: Arrays & Strings (40 MCQs)
- y[4];
- y[3]; ✓ Correct answer
- y[5];
- y(4);
-
What will be the number of elements in the following array? int arr[29];
Topic: Arrays & Strings (40 MCQs)
- 30
- 29 ✓ Correct answer
- 28
- 31
-
What will be the correct syntax to initialize all elements of a two-dimensional array to the value 0?
Topic: Arrays & Strings (40 MCQs)
- int arr[2][3] = {0,0};
- int arr[2][3] = {{0},{0}};
- int arr[2][3] = {0},{0};
- int arr[2][3] = {0}; ✓ Correct answer
-
Consider the following code segment. What will it display? int main() { int age[10] = {0}; cout << age; }
Topic: Arrays & Strings (40 MCQs)
- Values of all elements of the array
- Value of the first element of the array
- Starting address of the array ✓ Correct answer
- Address of the last array element
-
The memory address of the first element of an array is called:
Topic: Arrays & Strings (40 MCQs)
- Floor address
- Foundation address
- First address
- Base address ✓ Correct answer
-
The name of the array is a constant pointer which contains the memory address of the ________ of the array.
Topic: Arrays & Strings (40 MCQs)
- Last element
- First element ✓ Correct answer
- Middle element
- Largest element
-
We want to access an array in random order; which of the following approaches is better?
Topic: Arrays & Strings (40 MCQs)
- Pointers ✓ Correct answer
- Array index
- Both pointers and array index are better
- None of the given options
-
Whenever some number is added to an array name, it will jump as many ________ as the added number.
Topic: Arrays & Strings (40 MCQs)
- Rows
- Columns
- Elements ✓ Correct answer
- Bytes
-
The element multi[3][3] can also be accessed by ________.
Topic: Arrays & Strings (40 MCQs)
- *(*(multi+3)+3) ✓ Correct answer
- *(multi+3)+3
- *(*(multi+2)+2)
- multi[3+3]
-
char name[] = "Hello world"; In the above statement, memory of ________ characters will be allocated.
Topic: Arrays & Strings (40 MCQs)
- 11
- 12 ✓ Correct answer
- 10
- 13
-
How many bytes are occupied by declaring the following array of characters? char str[] = "programming";
Topic: Arrays & Strings (40 MCQs)
- 10
- 11
- 12 ✓ Correct answer
- 13
-
What will be the size of the following character array? char name[] = "Adeel";
Topic: Arrays & Strings (40 MCQs)
- 5
- 6 ✓ Correct answer
- 4
- 7
-
Null character is represented in C++ by:
Topic: Arrays & Strings (40 MCQs)
- \n
- \0 ✓ Correct answer
- \t
- \e
-
The ASCII code of the null character is ________.
Topic: Arrays & Strings (40 MCQs)
- 1
- 0 ✓ Correct answer
- 32
- 255
-
Which character is inserted at the end of a string to indicate the end of the string?
Topic: Arrays & Strings (40 MCQs)
- New line
- Tab
- Null ✓ Correct answer
- Carriage return
-
The string in the array is terminated by a ________.
Topic: Arrays & Strings (40 MCQs)
- Semicolon
- Null character ✓ Correct answer
- Space character
- New line character
-
Null character is used to indicate the ________ of a string.
Topic: Arrays & Strings (40 MCQs)
- Start
- End ✓ Correct answer
- Begin
- Middle
-
Individual characters in a string stored in an array can be accessed directly using the array ________.
Topic: Arrays & Strings (40 MCQs)
- Name
- Subscript ✓ Correct answer
- Pointer only
- Size
-
A ________ is an array of characters that can store the number of characters specified.
Topic: Arrays & Strings (40 MCQs)
- Integer array
- String ✓ Correct answer
- Structure
- Union
-
For which array should the size of the array be one more than the number of elements in the array?
Topic: Arrays & Strings (40 MCQs)
- int
- double
- float
- char ✓ Correct answer
-
In C/C++, the string constant is enclosed:
Topic: Arrays & Strings (40 MCQs)
- In curly braces
- In small braces
- In single quotes
- In double quotes ✓ Correct answer
-
A pointer is a variable which stores:
Topic: Pointers (15 MCQs)
- Data
- Memory address ✓ Correct answer
- Data type
- Values
-
Pointers are a special type of ________ in which a memory address is stored.
Topic: Pointers (15 MCQs)
- Constant
- Variable ✓ Correct answer
- Function
- Operator
-
When a pointer is incremented, it actually jumps the number of memory addresses:
Topic: Pointers (15 MCQs)
- According to its data type ✓ Correct answer
- 1 byte exactly
- 1 bit exactly
- A pointer variable cannot be incremented
-
How many bytes will the pointer intPtr of type int move in the following statement? intPtr += 3;
Topic: Pointers (15 MCQs)
- 3 bytes
- 6 bytes
- 12 bytes ✓ Correct answer
- 24 bytes
-
How many bytes will an integer type pointer intPtr jump in memory if the following statement is executed? intPtr += 2;
Topic: Pointers (15 MCQs)
- 2 bytes
- 4 bytes
- 8 bytes ✓ Correct answer
- 16 bytes
-
Suppose an integer type pointer contains the memory address 0x22f220. What will be the new memory address if we increment this pointer by one?
Topic: Pointers (15 MCQs)
- 0x22f221
- 0x22f224 ✓ Correct answer
- 0x22f228
- 0x22f220
-
Which of the following operators is used to access the value of a variable pointed to by a pointer?
Topic: Pointers (15 MCQs)
- * operator ✓ Correct answer
- -> operator
- && operator
- & operator
-
To get the value stored at a memory address, we use the ________.
Topic: Pointers (15 MCQs)
- Address operator
- Dereferencing operator ✓ Correct answer
- Reference operator
- Scope resolution operator
-
The statement cout << yptr; will show the ________ the yptr points to.
Topic: Pointers (15 MCQs)
- Value at
- Memory address ✓ Correct answer
- Data type of
- Name of
-
char **argv can be read as:
Topic: Pointers (15 MCQs)
- Pointer to char
- Pointer to pointer to char ✓ Correct answer
- Array of char
- Pointer to array of char
-
________ are the conventional names of the command line parameters of the main() function.
Topic: Pointers (15 MCQs)
- 'argc' and 'argv' ✓ Correct answer
- 'args' and 'vars'
- 'count' and 'vector'
- 'main1' and 'main2'
-
Which of the following is the correct statement for the following declaration? const int *ptr;
Topic: Pointers (15 MCQs)
- ptr is a constant pointer
- ptr is a constant integer pointer
- ptr is a constant pointer to int
- ptr is a pointer to const int ✓ Correct answer
-
Consider the following code segment. What will be the output? int arr[6] = {2, 3, 7, 4, 5, 6}; int *ptr1 = &arr[1]; int *ptr2 = &arr[4]; cout << (ptr2 - ptr1);
Topic: Pointers (15 MCQs)
- 3 ✓ Correct answer
- 9
- 12
- 2
-
What will be the correct syntax to assign an array named arr of 5 elements to a pointer ptr?
Topic: Pointers (15 MCQs)
- *ptr = arr;
- ptr = arr; ✓ Correct answer
- *ptr = arr[5];
- ptr = arr[5];
-
When an array element is passed to a function, it is passed by ________.
Topic: Pointers (15 MCQs)
- Reference
- Data type
- Value ✓ Correct answer
- Data
-
Structures are syntactically defined with the keyword ________.
Topic: Structures & Unions (5 MCQs)
- struct ✓ Correct answer
- structure
- class
- union
-
A record is a group of related ________.
Topic: Structures & Unions (5 MCQs)
- Files
- Fields ✓ Correct answer
- Functions
- Arrays
-
The syntax of a union is identical to ________.
Topic: Structures & Unions (5 MCQs)
- Structure ✓ Correct answer
- Class
- Function
- None of the given options
-
Dealing with structures and functions, passing by reference is the most economical method.
Topic: Structures & Unions (5 MCQs)
- True ✓ Correct answer
- False
-
The most efficient method of dealing with structure variables is to define the structure globally.
Topic: Structures & Unions (5 MCQs)
- True
- False ✓ Correct answer
-
C++ views each file as a sequential stream of ________.
Topic: File Handling (13 MCQs)
- Bytes ✓ Correct answer
- Bits
- 0's or 1's
- Words
-
We can read, write and manipulate the same file using ________.
Topic: File Handling (13 MCQs)
- iostream.h
- fstream.h ✓ Correct answer
- conio.h
- stdio.h
-
If a file is opened with the ios::out mode, then ________.
Topic: File Handling (13 MCQs)
- The file is opened for reading
- A new file is created ✓ Correct answer
- Data is appended at the end
- The file pointer moves to the end
-
Suppose we have a file with the name "myfile.txt". What will be the correct syntax of file opening for input?
Topic: File Handling (13 MCQs)
- myFile.open("myfile.txt", ios::in); ✓ Correct answer
- myFile.open("myfile.txt", ios::out);
- myFile.open(myfile.txt, ios::in);
- open.myFile("myfile.txt");
-
eof is used to check for the ________ of a file when a file is being read.
Topic: File Handling (13 MCQs)
- Start
- End ✓ Correct answer
- Middle
- Size
-
The ________ function gives the position of the next character to be read from a file.
Topic: File Handling (13 MCQs)
- tellp()
- tellg() ✓ Correct answer
- seekg()
- seekp()
-
We have opened a file stream myfile for reading. myfile.tellg() gives us the current get position of the file pointer. It returns a whole number of type ________.
Topic: File Handling (13 MCQs)
- int
- long ✓ Correct answer
- float
- char
-
The functions seekg() and seekp() require an argument of type ________ to let them know how many bytes to move forward or backward.
Topic: File Handling (13 MCQs)
- int
- long ✓ Correct answer
- float
- double
-
The function seekg() takes ________ parameter(s).
Topic: File Handling (13 MCQs)
- 0
- 1
- 2 ✓ Correct answer
- 3
-
The function write() takes ________ as parameter(s).
Topic: File Handling (13 MCQs)
- String of pointer type
- String of variable length, number of bytes to be read and flags
- Pointer array of characters and a delimiter
- String and number of bytes to be written ✓ Correct answer
-
While handling files, one can have ________ option(s).
Topic: File Handling (13 MCQs)
- Read the file
- Write in some file
- Read and write in the same file
- All of the given options ✓ Correct answer
-
An object of ________ can be created for saving the current position of any opened file before reading from the file.
Topic: File Handling (13 MCQs)
- streampos ✓ Correct answer
- streambuf
- fstream
- filebuf
-
In the statement aFile.seekg(-10L, ios::cur); the get pointer moves in the ________ direction.
Topic: File Handling (13 MCQs)
- Forward
- Backward ✓ Correct answer
- No movement
- To the beginning of the file
-
An instance of a class is called a/an ________.
Topic: Classes, Dynamic Memory & Macros (17 MCQs)
- Structure
- Object ✓ Correct answer
- Function
- Pointer
-
A constructor has ________.
Topic: Classes, Dynamic Memory & Macros (17 MCQs)
- A different name from the class
- The same name as the class ✓ Correct answer
- No name
- The name of the object
-
A default constructor takes ________.
Topic: Classes, Dynamic Memory & Macros (17 MCQs)
- One parameter
- Two parameters
- No parameter ✓ Correct answer
- Any number of parameters
-
In a class, we can have ________ constructor(s).
Topic: Classes, Dynamic Memory & Macros (17 MCQs)
- Only one
- Many ✓ Correct answer
- Exactly two
- None
-
For accessing data members, we use the ________ operator.
Topic: Classes, Dynamic Memory & Macros (17 MCQs)
- Arrow (->)
- Dot (.) ✓ Correct answer
- Scope resolution (::)
- Asterisk (*)
-
The friend functions are ________.
Topic: Classes, Dynamic Memory & Macros (17 MCQs)
- Members of the class
- Not members of the class ✓ Correct answer
- Members of another program
- Built-in functions
-
A friend function of a class is a function defined ________.
Topic: Classes, Dynamic Memory & Macros (17 MCQs)
- Inside that class
- Outside that class and that has the right to access all members of the class ✓ Correct answer
- In the main function only
- In a header file only
-
Initializing the data members within the class is ________ (in classic C++).
Topic: Classes, Dynamic Memory & Macros (17 MCQs)
- Allowed
- A syntax error ✓ Correct answer
- Optional
- Recommended
-
In C language, the region of memory allocated at run time is called the ________.
Topic: Classes, Dynamic Memory & Macros (17 MCQs)
- Stack
- Heap ✓ Correct answer
- Queue
- Static area
-
With the use of dynamic allocation of memory, the system resources can be ________.
Topic: Classes, Dynamic Memory & Macros (17 MCQs)
- Wasted
- Used efficiently ✓ Correct answer
- Ignored
- Locked
-
void *calloc(50, sizeof(int)) will return:
Topic: Classes, Dynamic Memory & Macros (17 MCQs)
- A memory chunk of 50 integers from the stack
- A memory chunk of 50 integers from the heap ✓ Correct answer
- 50 bytes of memory
- An integer value of 50
-
The calloc() function takes two arguments: the first argument is the ________ and the second argument is the ________.
Topic: Classes, Dynamic Memory & Macros (17 MCQs)
- Size of each element, number of elements
- Number of elements, size of each element ✓ Correct answer
- Total bytes, address of memory
- Address of memory, total bytes
-
The memory allocation in C++ is carried out with the help of the ________.
Topic: Classes, Dynamic Memory & Macros (17 MCQs)
- malloc function
- new operator ✓ Correct answer
- alloc function
- calloc function
-
The symbolic constant PI can be defined as:
Topic: Classes, Dynamic Memory & Macros (17 MCQs)
- const PI = 3.14;
- #define PI 3.14 ✓ Correct answer
- PI := 3.14;
- define PI 3.14;
-
A special name which is substituted in code by its definition, and as a result we get an expanded code, is called a ________.
Topic: Classes, Dynamic Memory & Macros (17 MCQs)
- Function
- Macro ✓ Correct answer
- Variable
- Loop
-
We can access a global variable ________.
Topic: Classes, Dynamic Memory & Macros (17 MCQs)
- Only inside main()
- Only inside the function where it is declared
- From anywhere in the program ✓ Correct answer
- Only in the same file after main()
-
Given the inline function: inline int max(int a, int b) { if (a > b) return a; return b; } In main(), x = 23 and y = 45, and the call max(x++, y++) is made. What will be the values of x and y after the call?
Topic: Classes, Dynamic Memory & Macros (17 MCQs)
- x = 23, y = 45
- x = 24, y = 46 ✓ Correct answer
- x = 24, y = 45
- x = 23, y = 46
-
Which programming tool is helpful in tracing the logical errors in a program?
Topic: Additional MCQs from Paper Topics (9 MCQs)
- Compiler
- Debugger ✓ Correct answer
- Linker
- Loader
-
What is the correct syntax of opening the file 'myFile.txt' in append ('app') mode using the ofstream variable 'out'?
Topic: Additional MCQs from Paper Topics (9 MCQs)
- out.open("myFile.txt", ios::app); ✓ Correct answer
- out.open("myFile.txt", ios::out);
- open.out("myFile.txt", ios::app);
- out.append("myFile.txt");
-
What is the result of the expression x = 2 + 3 * 4 - 4 / 2?
Topic: Additional MCQs from Paper Topics (9 MCQs)
- 10
- 12 ✓ Correct answer
- 9
- 18
-
What will be the output of the following code? int array[7], sum = 0; for (int i = 0; i < 7; i++) { array[i] = i; sum += array[i]; } cout << "Sum = " << sum;
Topic: Additional MCQs from Paper Topics (9 MCQs)
- Sum = 28
- Sum = 21 ✓ Correct answer
- Sum = 15
- Sum = 7
-
What will be the output of the following segment of C++ code? int A[5] = {1, 2, 3, 4}; for (int i = 0; i < 5; i++) { A[i] = 2 * A[i]; cout << A[i] << " "; }
Topic: Additional MCQs from Paper Topics (9 MCQs)
- 1 2 3 4 0
- 2 4 6 8 0 ✓ Correct answer
- 2 4 6 8 10
- 0 2 4 6 8
-
To which category of software do 'Compiler' and 'Interpreter' belong?
Topic: Additional MCQs from Paper Topics (9 MCQs)
- Application software
- System software ✓ Correct answer
- Utility software
- Device drivers
-
Suppose z is a variable of type int. What will be the result of z = 27 / 4?
Topic: Additional MCQs from Paper Topics (9 MCQs)
- 6.75
- 6 ✓ Correct answer
- 7
- 3
-
The statement seekg(-10L, ios::beg); contains an error because:
Topic: Additional MCQs from Paper Topics (9 MCQs)
- seekg() cannot take two arguments
- A negative offset cannot be used with ios::beg (beginning of the file) ✓ Correct answer
- The offset must be of type int
- ios::beg is used only with seekp()
-
A two-dimensional array arr has 3 rows and 4 columns. Which statements initialize the first element of all three rows with the value 2?
Topic: Additional MCQs from Paper Topics (9 MCQs)
- arr[0][0] = 2; arr[1][0] = 2; arr[2][0] = 2; ✓ Correct answer
- arr[0][1] = 2; arr[0][2] = 2; arr[0][3] = 2;
- arr[1][0] = 2; arr[2][0] = 2; arr[3][0] = 2;
- arr[0][0] = 2; arr[0][1] = 2; arr[0][2] = 2;
-
The name of a location in memory is called ______.
Topic: Programming Basics & Program Design
- Constant
- Variable ✓ Correct answer
- Cell
- Number
-
If x=11, and x%=3, than values of x will be
Topic: Programming Basics & Program Design
- 4
- 2 ✓ Correct answer
- 6
- 8
-
What is a key characteristic of an interpreter?
Topic: Programming Basics & Program Design
- It creates a separate executable file from the source code
- It compiles the whole program into bytecode before running
- It only works with assembly language
- It executes code line-by-line at runtime ✓ Correct answer
-
(x < 3) means in C++ that ______.
Topic: Programming Basics & Program Design
- x is less than 3 ✓ Correct answer
- x is greater than or equal to 3
- x is greater than 3
- x is equal to 3
-
Which of the following is a reserved word for data types in C/C++?
Topic: Programming Basics & Program Design
- integer
- int ✓ Correct answer
- character
- doubles
-
C was developed with the help of ______ language(s).
Topic: Programming Basics & Program Design
- BCPL
- BCPL and B ✓ Correct answer
- none of the above
-
C++ is a ______ language.
Topic: Programming Basics & Program Design
- High level ✓ Correct answer
- Lowlevel
- Machine
- Fourth Generation
-
We use ______ to include all those functions in our program which are located in different files.
Topic: Programming Basics & Program Design
- Linker ✓ Correct answer
- Loader
- Compiler
- Debugger
-
Mr. Ahmad sleeps thirty hours every day. This sentence is ______.
Topic: Programming Basics & Program Design
- Grammatically incorrect
- Grammatically correct but illogical ✓ Correct answer
- Illogical and grammatically incorrect
- Logical and grammatically correct
-
a= a +1; can be written as
Topic: Programming Basics & Program Design
- a + 1;
- a += 1; ✓ Correct answer
- a + a + 1;
- 1 + a = a;
-
A record is a group of related ______.
Topic: Programming Basics & Program Design
- Data
- Fields ✓ Correct answer
- Bytes
- Files
-
In shifting operations, if zero is inserted at the left most bit, the negative number will become a ______ number.
Topic: Programming Basics & Program Design
- Positive ✓ Correct answer
- Negative
- Absolute
- Smaller
-
Identify the logical error in the following if condition: if ((i < 5) && (i > 15))
Topic: Programming Basics & Program Design
- Condition is always true
- Condition is always false ✓ Correct answer
- & will be used instead of &&
- && cannot be used with if condition
-
Telling a computer what to do is called ______.
Topic: Programming Basics & Program Design
- Designing
- Implementing
- Programming ✓ Correct answer
- Compiling
-
Which of the following is not the sub-category of the system software?
Topic: Programming Basics & Program Design
- Operating system
- Device drivers
- Utilities
- None of the above ✓ Correct answer
-
We get ______ when 12 | 8 is evaluated, where | is the bit-wise OR operator.
Topic: Programming Basics & Program Design
- 12 ✓ Correct answer
- 10
- 14
-
Find out the logical error in the following lines of code: if (x = 10) cout << "x is 10";
Topic: Programming Basics & Program Design
- 10 should be enclosed in quotations
- There is no semicolon at the end of if condition
- Assignment operator should not be used for comparison ✓ Correct answer
- Variable x should not be inside parenthesis
-
______ are used to compile the code.
Topic: Programming Basics & Program Design
- Editors
- Debugger
- Linker
- Compiler ✓ Correct answer
-
!(x > 3) means in C++ that ______.
Topic: Programming Basics & Program Design
- x is less than 3
- x is less than or equal to 3 ✓ Correct answer
- x is greater than 3
-
Computers can understand only ______ language code.
Topic: Programming Basics & Program Design
- Machine ✓ Correct answer
- High level
- Natural
- Low level
-
Why do we use "cin"?
Topic: Programming Basics & Program Design
- To send data to printer
- To display output on the screen
- To display message
- To read data from keyboard ✓ Correct answer
-
Compiler translates a high level language program into ______ language code.
Topic: Programming Basics & Program Design
- C#
- Machine ✓ Correct answer
- Java
-
Learning to program is important because it develops ______ and ______ abilities.
Topic: Programming Basics & Program Design
- Analytical, writing
- Analytical, Problem solving ✓ Correct answer
- Reading, Writing
- Reading, Problem solving
-
It is the job of ______ to transfer the executable code from hard disk to main memory.
Topic: Programming Basics & Program Design
- Interpreter
- Debugger
- Linker
- Loader ✓ Correct answer
-
Using a segment of source code again by adding new functionalities with minor or without modification is termed as
Topic: Programming Basics & Program Design
- Code efficiency
- Code modification
- Code Generation
- Code Reusability ✓ Correct answer
-
______ is a precise sequence of steps to solve a particular problem.
Topic: Programming Basics & Program Design
- Analysis
- Program ✓ Correct answer
- Code
- Statement
-
if (a > b && a > c) then the condition will be true only if ______.
Topic: Programming Basics & Program Design
- Both a > b and a > c are false
- a > b is false and a > c is true
- a > b is true and a > c is false
- Both a > b and a > c are true ✓ Correct answer
-
Which one of the following is not a skill that we learn by designing programs?
Topic: Programming Basics & Program Design
- Critical reading
- Creative synthesis
- Analytical thinking
- Hardware performance knowledge ✓ Correct answer
-
______ returns true if c is a letter and false otherwise.
Topic: Programming Basics & Program Design
- int isalpha( int c ) ✓ Correct answer
- int isalnum( int c )
- int isdigit( int c )
- int isxdigit( int c )
-
Which of the following is equivalent to *(yptr + 4)?
Topic: Pointers
- *(yptr +3)
- yptr[3]
- *yptr + 4
- yptr[4] ✓ Correct answer
-
Which of the following is not a reserved word in C/C++?
Topic: Programming Basics & Program Design
- int
- float
- double
- sum ✓ Correct answer
-
To access rand(), which library is required to be included in the program?
Topic: Programming Basics & Program Design
- conio.h
- stdio.h
- stdlib.h ✓ Correct answer
- iostream.h
-
While programming, it is good to provide an easy to understand and easy to use interface; this programming skill is called ______.
Topic: Programming Basics & Program Design
- Scalability
- Usability ✓ Correct answer
- Reliability
- Sustainability
-
Word processor is a type of a/an ______.
Topic: Programming Basics & Program Design
- Operating system
- Application software ✓ Correct answer
- Device driver
- Utility software
-
The ______ statement allows us to select from multiple choices based on a set of fixed values for a given expression.
Topic: Programming Basics & Program Design
- switch ✓ Correct answer
- break
- continue
- goto
-
C is widely known as the development language of the ______ operating system.
Topic: Programming Basics & Program Design
- Windows
- Unix ✓ Correct answer
- Mac OS
- Linux
-
In a flow chart, the flow of control is represented by ______.
Topic: Programming Basics & Program Design
- Rectangle
- Circle
- Diamond
- Arrow ✓ Correct answer
-
For clarity and to force the order of evaluation in an expression, we should use ______.
Topic: Programming Basics & Program Design
- Brackets [ ]
- Parenthesis ( ) ✓ Correct answer
- Curly braces { }
- Quotation marks " "
-
The statement x += y can be interpreted as ______.
Topic: Programming Basics & Program Design
- Adding the value of y to the value of x and storing the result in x ✓ Correct answer
- Adding the value of x to the value of y and storing the result in y
- Subtracting the value of y from x and storing the result in x
- Multiplying the values of x and y and storing the result in x
-
Correcting the errors from a program is termed as _____________.
Topic: Programming Basics & Program Design
- Linking
- Loading
- Executing
- Debugging ✓ Correct answer
-
What happens to comment statements during the compilation process?
Topic: Programming Basics & Program Design
- They are ignored by the compiler ✓ Correct answer
- They cause syntax errors
- They are executed as logic
- They take up extra memory
-
Which tools are used to formulate program statements in a precise language?
Topic: Programming Basics & Program Design
- Pseudo code and flowcharting ✓ Correct answer
- Only hardware manuals
- Only compilers
- None of these
-
Software is categorized into which two main categories?
Topic: Programming Basics & Program Design
- Utility Software and System Software
- System Software and Application Software ✓ Correct answer
- Operating System and Device Drivers
- Application Software and Utility Software
-
The _____ is responsible for controlling the allocation and usage of hardware resources.
Topic: Programming Basics & Program Design
- Application Software
- Utility Software
- Device Driver
- Operating System ✓ Correct answer
-
Which tool allows a programmer to control a program while it is running to find logical errors?
Topic: Programming Basics & Program Design
- Preprocessor
- Loader
- Linker
- Debugger ✓ Correct answer
-
The process of including routines and functions to make a standalone executable code is called
Topic: Programming Basics & Program Design
- Debugging
- Linking ✓ Correct answer
- Preprocessing
- Loading
-
In the program execution process, the _____ processes the code first.
Topic: Programming Basics & Program Design
- Preprocessor ✓ Correct answer
- Loader
- Linker
- Compiler
-
What is the starting point of every C program?
Topic: Programming Basics & Program Design
- The main function ✓ Correct answer
- The first line of code
- The preprocessor
- None of these
-
The compiler creates _____ code and stores it on the disk.
Topic: Programming Basics & Program Design
- Object ✓ Correct answer
- Source
- Executable
- None of these
-
Which symbol is used to enclose the blocks of a program in C?
Topic: Programming Basics & Program Design
- ()
- {} ✓ Correct answer
- <>
- []
-
The output stream _____ takes data from the computer and sends it to the monitor.
Topic: Programming Basics & Program Design
- iostream
- printf
- cout ✓ Correct answer
- cin
-
What is a pictorial representation of a program using geometrical symbols called?
Topic: Programming Basics & Program Design
- Block
- Variable
- Flow chart ✓ Correct answer
- Syntax
-
What is the primary purpose of using header files in a C program?
Topic: Programming Basics & Program Design
- To increase the complexity of the program
- To store function prototypes and constants ✓ Correct answer
- To replace the main function body
- None of these
-
Header files are typically simple text files with which extension?
Topic: Programming Basics & Program Design
- .h ✓ Correct answer
- .txt
- .cpp
- .c
-
Which directive is used to include a header file in a program?
Topic: Programming Basics & Program Design
- #header
- #include ✓ Correct answer
- #define
- #import
-
______ will explain the function of a program.
Topic: Programming Basics & Program Design
- Comments ✓ Correct answer
- Debugger
- Compiler
- Linker
-
A variable declared within a code block becomes a ______ variable for that block.
Topic: Data Types, Variables & Operators
- Static
- Integer
- Local ✓ Correct answer
- Global
-
Which operator has the highest precedence in an expression?
Topic: Data Types, Variables & Operators
- () ✓ Correct answer
- +
- %
- *
-
A variable of character data type occupies - bytes in memory
Topic: Data Types, Variables & Operators
- 0
- 2
- 1 ✓ Correct answer
- 3
-
Which of the following is the correct operator to compare the values of two variables?
Topic: Data Types, Variables & Operators
- =
- == ✓ Correct answer
- :=
- *=
-
______ of a variable means the locations within a program from where it can be accessed.
Topic: Data Types, Variables & Operators
- Reference
- Visibility ✓ Correct answer
- Datatype
- Value
-
Remainder operator (%) is a/an operator.
Topic: Data Types, Variables & Operators
- Logical
- Relational
- Conditional
- Arithmetic ✓ Correct answer
-
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);
Topic: Data Types, Variables & Operators
- 15
- 17 ✓ Correct answer
- 12
- 11
-
What will be the value of 'a' and 'b' after executing the following statements? int a = 9; int b = a++; cout << a << b;
Topic: Data Types, Variables & Operators
- 9, 9
- 10, 10
- 9, 10
- 10, 9 ✓ Correct answer
-
What will be the output of the following code segment? char myName[] = "student ID"; int n = sizeof(myName); cout << n;
Topic: Data Types, Variables & Operators
- 10
- 11 ✓ Correct answer
- 12
- 15
-
After evaluating the expression X=10+3*4/2-1 the value of x will be
Topic: Data Types, Variables & Operators
- 5
- 10
- 15 ✓ Correct answer
- 20
-
Following is the declaration of a ______ array. int ar[2][2][2];
Topic: Arrays & Strings
- 1-Dimensional
- 2-Dimensional
- 3-Dimensional ✓ Correct answer
- None of the given
-
Which of the following options is correct to complete the declaration of the function? ______ functionName(parameter1, parameter2) { // code to be executed }
Topic: Functions & References
- void functionName ✓ Correct answer
- int functionName;
- functionName void
- void (functionName)
-
There is a pointer variable named ptr of type float. Which type of variable address can be stored by ptr?
Topic: Data Types, Variables & Operators
- int
- float ✓ Correct answer
- char
- double
-
X is an integer variable; what does X++ mean?
Topic: Data Types, Variables & Operators
- Add 1 two times in X value
- Add 1 in X value ✓ Correct answer
- Add 2 in X value
- None of these
-
= operator is used for ______.
Topic: Data Types, Variables & Operators
- Decision making
- Assigning values to variables ✓ Correct answer
- Checking equality
- Comparison
-
If int a = 50; then the value of a /= 3; will be ______.
Topic: Data Types, Variables & Operators
- 15
- 18
- 16 ✓ Correct answer
-
NOT operator is a ______.
Topic: Data Types, Variables & Operators
- Single input operator ✓ Correct answer
- Binary operator
- Ternary operator
- None of the given
-
< and > both are ______ operators.
Topic: Data Types, Variables & Operators
- Arithmetic
- Relational ✓ Correct answer
- Logical
- Mathematical
-
What will be the correct syntax of declaration of the following statement? "ptr is a pointer to const int"
Topic: Data Types, Variables & Operators
- int const *ptr
- int *const ptr
- const int *ptr ✓ Correct answer
- const *int ptr
-
Which operator uses the ^ sign?
Topic: Data Types, Variables & Operators
- Bit-wise OR
- Exclusive OR ✓ Correct answer
- AND Operator
- NOT operator
-
When the logical operator OR (||) combines two expressions exp1 and exp2, then the result will be false only ______.
Topic: Data Types, Variables & Operators
- When exp1 is false and exp2 is true
- When exp1 is true and exp2 is false
- When both exp1 and exp2 are false ✓ Correct answer
- When both exp1 and exp2 are true
-
What will be the values of variables x and y after executing the following code if x = 33 and y = 19? if (x % y != 0) x++; y--;
Topic: Data Types, Variables & Operators
- X=22,y=14
- x=14,y=36
- x=34,y=18 ✓ Correct answer
- x=30,y=36
-
What will be the result of arithmetic expression 6 + 48/4 * 3?
Topic: Data Types, Variables & Operators
- 41
- 42 ✓ Correct answer
- 40.5
- 10
-
Which of the following is the right syntax to declare a variable in C++?
Topic: Data Types, Variables & Operators
- DataType VariableName; ✓ Correct answer
- (DataType)VariableName;
- DataType =VariableName;
- VariableName Datatype;
-
If int sum = 54; then the value of the statement sum = sum - 3; is ______.
Topic: Data Types, Variables & Operators
- 51 ✓ Correct answer
- 52
- 50
- 57
-
What is the correct syntax of an array declaration, of double data type, for size 10 and initialized to value 0?
Topic: Data Types, Variables & Operators
- arr[10] = [0.0];
- double arr[] = 0.0;
- double arr[10] = {0.0}; ✓ Correct answer
- double arr[10] = 0.0;
-
Identify the correct option which is used for calling the function float area(int).
Topic: Data Types, Variables & Operators
- area(&num);
- area(num); ✓ Correct answer
- area(int num);
- area(*num);
-
Which of the following is not an example of int data type?
Topic: Data Types, Variables & Operators
- -32
- 65531
- -4.0 ✓ Correct answer
-
Which of the following can not be a variable name?
Topic: Data Types, Variables & Operators
- area
- _area
- 10area ✓ Correct answer
- area2
-
According to c++ norms, the first character of a variable name must be an alphabet or
Topic: Data Types, Variables & Operators
- Underscore ✓ Correct answer
- Special character
- Digit
- None of the given options
-
Which of the following will be the most appropriate data type to store the value 63.547?
Topic: Data Types, Variables & Operators
- Integer
- Character
- Short
- Float ✓ Correct answer
-
How much memory does the 'int' data type typically occupy?
Topic: Data Types, Variables & Operators
- 1 byte
- 4 bytes ✓ Correct answer
- 2 bytes
- 8 bytes
-
The 'short' data type has a size of _____ bytes.
Topic: Data Types, Variables & Operators
- 2 ✓ Correct answer
- 8
- 4
- 1
-
Which data type is used to store real numbers and uses four bytes?
Topic: Data Types, Variables & Operators
- float ✓ Correct answer
- long
- double
- int
-
If you need to store a very large real number that exceeds four bytes, you should use:
Topic: Data Types, Variables & Operators
- double ✓ Correct answer
- int
- float
- short
-
What is the result of the integer division 5 / 2 in C?
Topic: Data Types, Variables & Operators
- 3
- 2.5
- 0
- 2 ✓ Correct answer
-
The modulus operator (%) can only be used with _____ operands.
Topic: Data Types, Variables & Operators
- double
- char
- float
- integer ✓ Correct answer
-
Which data type range is -32768 to 32767?
Topic: Data Types, Variables & Operators
- long
- int
- short ✓ Correct answer
- float
-
Which of the following is NOT a valid way to write a C statement?
Topic: Data Types, Variables & Operators
- x + 5 = y; ✓ Correct answer
- cout << x;
- int x = 5;
- x = 5 + 10;
-
What happens to the decimal portion when two integers are divided in C?
Topic: Data Types, Variables & Operators
- It is rounded down
- It is truncated ✓ Correct answer
- It is ignored
- It is rounded up
-
The increment operator ++ is a _____ operator that increases the value of its operand by 1.
Topic: Data Types, Variables & Operators
- binary
- ternary
- unary ✓ Correct answer
- None of these
-
How many bits are used to store a single character in memory?
Topic: Data Types, Variables & Operators
- 8 bits ✓ Correct answer
- 4 bits
- 16 bits
- 32 bits
-
Which operator is used to access the data members of a structure variable?
Topic: Structures & Unions
- &
- . ✓ Correct answer
- ->
- ::
-
Which of the following is NOT a bitwise operator?
Topic: Data Types, Variables & Operators
- && ✓ Correct answer
- &
- |
- ~
-
How does the & operator differ from the && operator?
Topic: Data Types, Variables & Operators
- & operates on bits while && operates on conditions ✓ Correct answer
- & returns true/false while && returns a bit pattern
- & operates on conditions while && operates on bits
- None of these
-
The Exclusive OR operator (^) returns 1 when:
Topic: Data Types, Variables & Operators
- Both bits are 1
- Both bits are 0
- One input is 0 and the other is 1 ✓ Correct answer
- None of these
-
The _____ operator is a unary operator that inverts the bits of the input number.
Topic: Data Types, Variables & Operators
- XOR
- NOT ✓ Correct answer
- OR
- AND
-
Shifting a bit to the left in the binary system is equivalent to:
Topic: Data Types, Variables & Operators
- Multiplying by 2 ✓ Correct answer
- Adding 2
- Dividing by 2
- None of these
-
Shifting a bit to the right in the binary system is equivalent to:
Topic: Data Types, Variables & Operators
- Dividing by 2 ✓ Correct answer
- Multiplying by 2
- Subtracting 2
- None of these
-
If you right shift 12 twice, the result is:
Topic: Data Types, Variables & Operators
- 6
- 3 ✓ Correct answer
- 24
- 48
-
The != operator is used to check whether the operand on the left-hand side is ______ the operand on the right-hand side.
Topic: Data Types, Variables & Operators
- Equal to
- Not equal to ✓ Correct answer
- Greater than
- Less than
-
______ variables are those that are defined outside of main.
Topic: Data Types, Variables & Operators
- Local
- Global ✓ Correct answer
- Static
- Register
-
If y = 20 and z = y++, then the value of z will be ______.
Topic: Data Types, Variables & Operators
- 19
- 20 ✓ Correct answer
- 21
- 22
-
What will be 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; }
Topic: Decision Structures (if & switch)
- none of above
- apple banana mango any fruit ✓ Correct answer
- apple
- apple any fruit
-
What is the output of the following code if the 3rd 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; }
Topic: Decision Structures (if & switch)
- mango
- mango any fruit ✓ Correct answer
- apple
- none of the above
-
______ statement is used to terminate the processing of a particular case and exit from the switch structure.
Topic: Decision Structures (if & switch)
- if
- goto
- break ✓ Correct answer
- continue
-
______ construct is used to execute a set of instructions when a condition is true and another set when it is false.
Topic: Decision Structures (if & switch)
- If
- else
- if/else ✓ Correct answer
- else/if
-
Find the syntax error in the following piece of code: if (x > y); cout << "x is greater than y"; else cout << "y is greater than x";
Topic: Decision Structures (if & switch)
- Braces not given for if and else blocks
- Semicolon should not be after the if statement ✓ Correct answer
- Condition in the if statement is wrong
- No error in the code
-
When the if statement consists of more than one statement, then enclosing these statements in braces is ______.
Topic: Decision Structures (if & switch)
- Relevant
- Not required
- Compulsory ✓ Correct answer
-
Which of the following logical operators returns true only if both conditions are true?
Topic: Decision Structures (if & switch)
- !(NOT)
- && (AND) ✓ Correct answer
- || (OR)
- == (Equality)
-
______ is a multiple-selection construct which makes the code more efficient and easy to read and understand.
Topic: Decision Structures (if & switch)
- multiple-if
- switch ✓ Correct answer
- if-else
- else-if
-
In a switch statement, the variable or expression must evaluate to which type?
Topic: Decision Structures (if & switch)
- boolean
- string
- integer ✓ Correct answer
- float
-
The _____ statement is executed if no case matches the value of the switch statement.
Topic: Decision Structures (if & switch)
- break
- goto
- continue
- default ✓ Correct answer
-
What happens if a break statement is missing in a switch case?
Topic: Decision Structures (if & switch)
- The default case executes
- The program exits
- The program crashes
- The next case executes (fall through) ✓ Correct answer
-
______ loop is mostly used to perform repetition of tasks for a known number of times.
Topic: Loops
- Nested Loop
- For ✓ Correct answer
- While
- Do-While
-
A while loop may execute ______ or more times.
Topic: Loops
- 1
- 0 ✓ Correct answer
- 2
- 3
-
In a while loop, the loop counter is initialized ______.
Topic: Loops
- Inside the loop
- Before entering the loop ✓ Correct answer
- After the loop
- At any place
-
A ______ structure specifies that an action is to be repeated while some condition remains true.
Topic: Loops
- Control
- Logical
- Repetition ✓ Correct answer
- Relational
-
In a while loop, the condition is checked ______ the execution of the loop body.
Topic: Loops
- After
- Before ✓ Correct answer
- At any time
- During
-
When the break statement is encountered in a loop's body, it transfers the control ______ from the current loop.
Topic: Loops
- Inside
- To continue statement
- To break statement
- Outside ✓ Correct answer
-
What will be the output of the following while loop? int counter = 0; while (counter < 15) cout << counter << " "; counter++;
Topic: Loops
- Infinite loop ✓ Correct answer
- Compile time error
- 12 3 4
- 123 4 5
-
The condition in loop should be a(n)
Topic: Loops
- Constant Expression
- Boolean Expression ✓ Correct answer
- Primary Expression
- Arithmetic Expression
-
What is the correct syntax for a while loop?
Topic: Loops
- while (statement1) { Logical Expression; }
- while (Logical Expression) { statement1; } ✓ Correct answer
- while (Logical Expression) statement1; statement2;
- while { Logical Expression } (statement1;)
-
If you omit curly braces in a while loop, how many statements are repeated?
Topic: Loops
- All statements until the end of main
- None of the statements
- Only the first statement after the while ✓ Correct answer
- All statements in the program
-
What happens if you do not change the loop variable inside a while loop?
Topic: Loops
- The program terminates
- A compile-time error occurs
- An infinite loop occurs ✓ Correct answer
- The loop executes only once
-
Which loop structure ensures that a block of statements is executed at least once?
Topic: Loops
- for loop
- while loop
- do-while loop ✓ Correct answer
- None of these
-
What is the correct syntax for the do-while structure?
Topic: Loops
- do ( condition ) { statement(s); };
- while ( condition ) { statement(s); } do;
- do while ( condition ) { statement(s); }
- do { statement(s); } while ( condition ); ✓ Correct answer
-
What is the primary difference between while and do-while loops?
Topic: Loops
- The use of variables
- The number of conditions
- The placement of the condition check ✓ Correct answer
- None of these
-
What does the continue statement do in a for loop?
Topic: Loops
- Starts the next iteration ✓ Correct answer
- Exits the switch
- Jumps to the beginning of the program
- Terminates the loop
-
At the ______ phase, we try to break up the problem into functional units.
Topic: Functions & References
- testing phase
- design phase ✓ Correct answer
- Implementation phase
- analysis phase
-
The data type before a function name represents its,
Topic: Functions & References
- Return Type ✓ Correct answer
- Function data
- Function arguments
- Function name
-
When we call a function, its control ______.
Topic: Functions & References
- transfers to its prototype
- transfers to its definition ✓ Correct answer
- returns to the statement following the function call
- The compiler stops execution of the whole program
-
A function's prototype is written ______ the function call.
Topic: Functions & References
- After
- Before ✓ Correct answer
- With
- At the end of
-
To read command line argument the main() function itself must be given-
Topic: Functions & References
- 1
- 2 ✓ Correct answer
- 3
- 4
-
__________ contains functions for manipulations of character data.
Topic: Functions & References
- Ctype.h ✓ Correct answer
- Iostream.h
- String.h
- None of the given
-
The function write() takes as parameter(s)
Topic: File Handling
- String of pointer type
- String of variable length, number of bytes to be read and last position
- Pointer, array of characters and a delimiter
- Character array and number of bytes to be written ✓ Correct answer
-
_________ Keyword is used to return some value from a function.
Topic: Functions & References
- Break
- Goto
- Continue
- Return ✓ Correct answer
-
______ function is used to find the number of characters in a string.
Topic: Functions & References
- str()
- str_len()
- strlength()
- strlen() ✓ Correct answer
-
In call by reference, ______ of a variable is passed to the called function.
Topic: Functions & References
- Name
- Data type
- Value
- Address ✓ Correct answer
-
A function is a block of statements that can be defined once and used ______ in the program.
Topic: Functions & References
- One time
- Two times
- Three times
- As many times as user wants ✓ Correct answer
-
From the following, which one is the range of the random number generator function rand()?
Topic: Functions & References
- 0-32768
- 1-32768
- 0-32767 ✓ Correct answer
- 1-32767
-
A program statement that invokes a function is called a ______.
Topic: Functions & References
- Function declaration
- Function call ✓ Correct answer
- Function definition
- Function prototype
-
Which one of the following functions is not included in the ctype.h header file?
Topic: Functions & References
- isdigit(int c)
- isxdigit(int c)
- tolower(int c)
- getdigit(int c) ✓ Correct answer
-
What will be the range of numbers generated by the function rand() % 9?
Topic: Functions & References
- 0 to 9
- 1 to 9
- 0 to 8 ✓ Correct answer
- 1 to 8
-
Preprocessor program perform its function before ______ phase takes place.
Topic: Functions & References
- Editing
- Linking
- Compiling ✓ Correct answer
- Loading
-
In C/C++, by default arguments are passed by ______ to a function.
Topic: Functions & References
- Reference
- Value ✓ Correct answer
- Type
- Data
-
Which of the following function calls is 'call by reference' for the following prototype? int add(int*);
Topic: Functions & References
- add(&x) ✓ Correct answer
- add(int x);
- add(x);
- add(*x);
-
Top-down designing mechanism is based on which principle?
Topic: Functions & References
- Code reuse
- Information hiding
- Divide and conquer ✓ Correct answer
- Parallel processing
-
What is the return_value_type for functions that do not return any value?
Topic: Functions & References
- int
- empty
- void ✓ Correct answer
- null
-
If no return_value_type is mentioned for a function, what is the default return type?
Topic: Functions & References
- void
- float
- double
- int ✓ Correct answer
-
The declaration of a function is also known as the _____.
Topic: Functions & References
- Function prototype ✓ Correct answer
- Function call
- Function variable
- Function body
-
What happens if you use a function without declaring it first?
Topic: Functions & References
- The function is automatically defined
- The compiler ignores it
- The compiler gives an error ✓ Correct answer
- The program runs faster
-
Which of these is a valid way to call a function?
Topic: Functions & References
- result = square(5); ✓ Correct answer
- int square(5);
- square(5) = result;
- None of these
-
A recursive function is a special type of function that can call _____.
Topic: Functions & References
- itself ✓ Correct answer
- the main function
- another file
- none of these
-
A recursive function must have a _____ case to indicate when the function will terminate.
Topic: Functions & References
- final
- base ✓ Correct answer
- return
- stop
-
Which function is used to initialize the random number generator with a different value?
Topic: Functions & References
- srand() ✓ Correct answer
- time()
- rand()
- None of these
-
Which function converts its uppercase letter argument into a lowercase letter?
Topic: Functions & References
- toupper
- isdigit
- tolower ✓ Correct answer
- isalpha
-
Which of the following function calls is 'call by value' for the following prototype? float add(int);
Topic: Functions & References
- add(&x);
- add(x); ✓ Correct answer
- add(int x);
- add(*x);
-
How can we declare an array of characters whose size is 12 with array name "country"?
Topic: Arrays & Strings
- char country[12]; ✓ Correct answer
- char country[11];
- char[12] country;
- char country[0-11];
-
When we access a multidimensional array, each array index is surrounded by ______.
Topic: Arrays & Strings
- Commas
- Brackets [ ] ✓ Correct answer
- Single quotes
- Double quotes
-
Following is an array of ____ rows and _____ columns. int num[3][4];
Topic: Arrays & Strings
- 4 and 4
- 3 and 4 ✓ Correct answer
- 4 and 3
- 3 and 3
-
Array indexes start from-
Topic: Arrays & Strings
- 0 ✓ Correct answer
- 1
- 4
- 8
-
______ character is used to indicate the end of the string.
Topic: Arrays & Strings
- Newline
- Blank space
- Null ✓ Correct answer
-
What will be the output of the following code? string name[4] = {"Ali", "Bilal", "Omer", "Ayesha"}; cout << name[0];
Topic: Arrays & Strings
- Ali ✓ Correct answer
- Bilal
- Omer.
- Ayesha
-
Each array declaration must provide the information about all these things except ______.
Topic: Arrays & Strings
- Name of the array
- Type of data stored in the array
- The location of the first element to be stored ✓ Correct answer
- Number of elements of the array
-
What will be the output of the following code? string grade[3] = {"A", "B", "C"}; grade[2] = "F"; cout << grade[2];
Topic: Arrays & Strings
- F ✓ Correct answer
- A
- C
- D
-
Which of the following option is correct about array?
Topic: Arrays & Strings
- Array is not used to store elements.
- Elements in an array cannot be sorted.
- Different types of elements can be stored in an array.
- Only one type of elements can be stored in an array ✓ Correct answer
-
Suppose we have int y[10]; To access the 4th element of the array we write ______.
Topic: Arrays & Strings
- y[2];
- y[4];
- y[3]; ✓ Correct answer
- none of given
-
How do we declare an array of integer data whose size is 20 with array name "count"?
Topic: Arrays & Strings
- int count[19];
- int count[20]; ✓ Correct answer
- float count[20];
- int count[21];
-
______ is an array of characters that can store the number of characters specified.
Topic: Arrays & Strings
- Char
- String ✓ Correct answer
- Multidimensional array
- Datatype
-
Declaration of a two-dimensional array of integers having 3 rows and 5 columns is ______.
Topic: Arrays & Strings
- int arr[3][5]; ✓ Correct answer
- int arr(5, 3);
- int [3], [5] arr;
- int arr[5][3];
-
If an array has 50 elements, what is the allowable range of subscripts?
Topic: Arrays & Strings
- 0-49 ✓ Correct answer
- 1-49
- 0-50
- 1-50
-
In case of a two-dimensional array, if you add some number in the two-dimensional array name, it will jump to the next ______.
Topic: Arrays & Strings
- row ✓ Correct answer
- column
- character.
- array
-
We want to access an array in random order; which of the following approaches is better?
Topic: Arrays & Strings
- Pointers ✓ Correct answer
- Array index
- Both pointers and array index are better
- None of the given
-
Which function is used to locate the first occurrence of a character in a string?
Topic: Arrays & Strings
- strchr() ✓ Correct answer
- strstr()
- strtok()
- strlen()
-
How many bytes are occupied by declaring the following array of characters? char str[] = "programming";
Topic: Arrays & Strings
- 10
- 11
- 12 ✓ Correct answer
- 13
-
To be able to copy one array into another, what must be true?
Topic: Arrays & Strings
- Same data type but different size
- Different data type but same size
- Same data type and same size ✓ Correct answer
- None of these
-
The size of a character array should be _____ more than the number of characters you want to store.
Topic: Arrays & Strings
- one ✓ Correct answer
- zero
- two
- none of these
-
Binary search algorithm only applies to arrays that are _____.
Topic: Arrays & Strings
- sorted ✓ Correct answer
- unsorted
- empty
- none of these
-
To pass an array to a function, you must pass the name of the array and the _____ of the array.
Topic: Arrays & Strings
- index
- type
- size ✓ Correct answer
- address
-
When passing an array to a function, the _____ of the array is passed.
Topic: Arrays & Strings
- address ✓ Correct answer
- copy
- value
- none of these
-
How do you access an element in a two-dimensional array?
Topic: Arrays & Strings
- a[row][col] ✓ Correct answer
- a[row, col]
- a(row, col)
- a[col][row]
-
When passing a 2D array to a function, you must specify the _____.
Topic: Arrays & Strings
- data type
- number of rows
- number of columns ✓ Correct answer
- total size
-
All string manipulation functions are defined in which header file?
Topic: Arrays & Strings
- stdlib.h
- ctype.h
- iostream.h
- string.h ✓ Correct answer
-
Which function appends string s2 to array s1, overwriting s1's null character?
Topic: Arrays & Strings
- strlen
- strcpy
- strcat ✓ Correct answer
- strcmp
-
If s1 < s2, the strcmp function returns a _____ number.
Topic: Arrays & Strings
- negative ✓ Correct answer
- null
- positive
- zero
-
The atoi function converts a string to a _____.
Topic: Arrays & Strings
- int ✓ Correct answer
- double
- char
- long
-
Which function compares up to n characters of two strings?
Topic: Arrays & Strings
- strncat
- strcmp
- strncpy
- strncmp ✓ Correct answer
-
Which function is used to convert a string to a double?
Topic: Arrays & Strings
- atof ✓ Correct answer
- atol
- atoi
- None of these
-
In the transpose of a matrix, the first row becomes the ______.
Topic: Arrays & Strings
- Last column
- First column ✓ Correct answer
- First row
- Diagonal
-
How much space does the null character '\0' take in the memory?
Topic: Arrays & Strings
- 0 bytes
- 1 byte ✓ Correct answer
- 2 bytes
- 4 bytes
-
Base address is the memory address of the ______ element of an array.
Topic: Pointers
- 1st ✓ Correct answer
- 3rd
- 4th
- 2nd
-
Pointer points to a particular
Topic: Pointers
- Value
- Variable
- Data type
- Memory address ✓ Correct answer
-
In the case of pointer to pointer or __________, the first pointer contains the address of the second pointer, which contains the address of the variable, which contains the desired value.
Topic: Pointers
- Different
- Float and double
- Single dereference
- Double dereference ✓ Correct answer
-
dereferencing operator is represented by _______
Topic: Pointers
- +
- * ✓ Correct answer
- -
- None
-
char **argv can be read as ______.
Topic: Pointers
- Pointer to Pointer
- Pointer to Char
- Pointer to Pointer to Char ✓ Correct answer
- None of the given
-
The name of the array is a constant pointer which contains the memory address of the ______ of the array.
Topic: Pointers
- First element ✓ Correct answer
- Last element
- Second element
- None of the given
-
Which of the following is a correct way to assign the address of the first element of array to pointer? int data[10];
Topic: Pointers
- int *ptr = data; ✓ Correct answer
- int *ptr = &data;
- int *ptr = data[0];
- int *ptr = data[2];
-
The increment of a pointer depends on its___________.
Topic: Pointers
- Values
- Variable
- Data type ✓ Correct answer
- None of the given
-
What is the output of the following code? int data[10] = {10, 20, 30, 40, 50, 60, 70, 80, 90, 100}; int *xptr = &data[4]; int *yptr = &data[6]; cout << xptr + yptr++;
Topic: Pointers
- 110
- 120
- 130
- Syntax error ✓ Correct answer
-
The _____ operator is used in C to get the address of a variable.
Topic: Pointers
- %
- & ✓ Correct answer
- #
- *
-
The _____ operator is used to get the value stored at a memory address.
Topic: Pointers
- address
- logical
- assignment
- dereferencing ✓ Correct answer
-
The statement int *const myptr = &x declares:
Topic: Pointers
- A pointer to a constant integer
- A constant pointer to a constant integer
- A constant pointer to an integer ✓ Correct answer
- None of these
-
The statement const int *myptr = &x describes:
Topic: Pointers
- A pointer to a constant integer ✓ Correct answer
- A constant pointer to a constant integer
- A constant pointer to an integer
- None of these
-
If you declare int *ptr = 0, what is the pointer called?
Topic: Pointers
- An integer pointer
- A dangling pointer
- A null pointer ✓ Correct answer
- None of these
-
What does the statement *num = 5 do if num is a pointer?
Topic: Pointers
- Assigns 5 to the pointer variable
- Assigns 5 to the address of the pointer
- Assigns 5 to the memory location pointed to by num ✓ Correct answer
- None of these
-
Which of the following is a correct way to declare a pointer to a double?
Topic: Pointers
- ptr *double;
- *double ptr;
- double *ptr; ✓ Correct answer
- double ptr;
-
The expression (*yptr)++ is read as:
Topic: Pointers
- Decrement the value at yptr
- Increment the value yptr points to ✓ Correct answer
- Increment the pointer address
- None of these
-
What happens if you try to add two pointers together in C?
Topic: Pointers
- It adds the values stored
- The compiler shows an error ✓ Correct answer
- It returns the total address
- None of these
-
If an integer occupies 4 bytes, incrementing an integer pointer will increase its address by _____ bytes.
Topic: Pointers
- 4 ✓ Correct answer
- 2
- 1
- None of these
-
If yptr points to the first element of an array of integers, what does yptr++ do?
Topic: Pointers
- Points to the second element of the array ✓ Correct answer
- Points to the previous memory address
- Increments the value of the first element
- None of these
-
If you have two pointers to the same integer array, what does subtracting them return?
Topic: Pointers
- The sum of their addresses
- The number of array elements between them ✓ Correct answer
- The number of bytes between them
- None of these
-
Which of these is a valid way to access the 6th element of an array y using a pointer yptr?
Topic: Pointers
- *(yptr + 5) ✓ Correct answer
- *(yptr + 6)
- yptr(5)
- None of these
-
What is the result of (yptr2 - yptr1) if yptr1 points to index 0 and yptr2 points to index 3?
Topic: Pointers
- 1
- 3 ✓ Correct answer
- 2
- None of these
-
What is the nature of an array name when used as a pointer?
Topic: Pointers
- A pointer to pointer
- A variable pointer
- A constant pointer ✓ Correct answer
- None of these
-
What is the result of '**multi' for a two-dimensional array?
Topic: Pointers
- The value of the first element ✓ Correct answer
- The address of the array
- The address of the first row
- None of these
-
Suppose that an integer pointer contains the memory address 0x22f220. What will be the new memory address if we increment this pointer by one?
Topic: Pointers
- 0x22f221
- 0x22f222
- 0x22f223
- 0x22f224 ✓ Correct answer
-
Which is not true regarding structures?
Topic: Structures & Unions
- We can declare arrays of structure
- We can take the sizeof structure
- We can't declare pointers to structure ✓ Correct answer
- Both b & c
-
A structure is a collection of _____________under a single name.
Topic: Structures & Unions
- Array
- Pointer
- Datatype
- Variables ✓ Correct answer
-
Which is the correct syntax to define a structure named 'student'?
Topic: Structures & Unions
- structure student { // variables }
- struct student { // variables } ✓ Correct answer
- structure student // variables
- struct student // variables
-
When accessing a structure member, the identifier to the left of the dot operator is the name of ______.
Topic: Structures & Unions
- Structure variable ✓ Correct answer
- Structure member
- Structure tag
- Structure data
-
The syntax of ______ is identical to the syntax of a structure.
Topic: Structures & Unions
- union ✓ Correct answer
- class
- function
- loop
-
A structure is a collection of variables under a single name. These variables are called:
Topic: Structures & Unions
- Union members
- Class members
- Function members
- Data members ✓ Correct answer
-
What is the correct syntax to declare an array of 100 student structures?
Topic: Structures & Unions
- student[100] s;
- array<student> s(100);
- s student[100];
- student s[100]; ✓ Correct answer
-
When assigning one structure to another (e.g., s1 = s2), what happens?
Topic: Structures & Unions
- Only the address is copied
- All data members are copied ✓ Correct answer
- Only the first member is copied
- The assignment fails
-
If 'sptr' is a pointer to a structure, which syntax is used to access a member?
Topic: Structures & Unions
- sptr::member
- sptr.member
- sptr->member ✓ Correct answer
- sptr[member]
-
How much memory is allocated to a union?
Topic: Structures & Unions
- Fixed 4 bytes
- Size of the largest member ✓ Correct answer
- Size of the smallest member
- Sum of all members
-
What is the primary difference between a structure and a union?
Topic: Structures & Unions
- Structures are smaller
- Structures share memory
- Unions share memory ✓ Correct answer
- Unions have more members
-
If you have 'student s[100]', what is the correct way to access the name of the first student?
Topic: Structures & Unions
- s[0].name ✓ Correct answer
- s.name
- s[1].name
- s.name[0]
-
If an integer is 4 bytes and a char is 1 byte, what is the size of a union containing both?
Topic: Structures & Unions
- 8 bytes
- 1 byte
- 4 bytes ✓ Correct answer
- 5 bytes
-
If you have a pointer 'sptr' to a structure, what is the correct alternative to 'sptr->name'?
Topic: Structures & Unions
- sptr(name)
- sptr.name
- *sptr.name
- (*sptr).name ✓ Correct answer
-
In ______, we have different data members and all of these have their own memory space.
Topic: Structures & Unions
- Structures ✓ Correct answer
- Unions
- Classes
- Functions
-
ofstream is used for ______.
Topic: File Handling
- Input file stream
- Output file stream ✓ Correct answer
- Input and output file stream
- All of the given
-
A file opened with ____ is used for input and cannot be used for output.
Topic: File Handling
- ifstream ✓ Correct answer
- Ostream
- Istream
- Fstream
-
Which of the following is not a file opening mode?
Topic: File Handling
- ios::in
- ios::out
- ios::ate
- ios::truncate ✓ Correct answer
-
Which statement is used to close a file?
Topic: File Handling
- myFile.off();
- myFile.shut();
- myFile.close(); ✓ Correct answer
- myFile.closefile();
-
______ is used for input file or for reading from the file.
Topic: File Handling
- tellg() ✓ Correct answer
- seekg()
- tellp()
- seekp()
-
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 ______.
Topic: File Handling
- long ✓ Correct answer
- int
- short
- double
-
Which of the following is the default mode of opening using the ofstream class?
Topic: File Handling
- ios::in
- ios::out ✓ Correct answer
- ios::app
- ios::trunc
-
If a file is opened with ios::out mode, then ______.
Topic: File Handling
- File is deleted
- We can write in this file ✓ Correct answer
- Content of file is discarded
- A new file is created
-
______ function gives the position of the next character to be read from that file.
Topic: File Handling
- tellp()
- tellg() ✓ Correct answer
- seekg()
- seekp()
-
______ function is used to determine the next position to write a character while writing into a file.
Topic: File Handling
- tellg()
- seekg()
- seekp()
- tellp() ✓ Correct answer
-
eof is used to check for the ______ of file when a file is being read.
Topic: File Handling
- Start
- End ✓ Correct answer
- Middle
- Name
-
______ is used for output during the process of writing to the file.
Topic: File Handling
- seekg()
- tellg()
- seekp() ✓ Correct answer
- tellp()
-
Which header file must be included to use the functions tolower() and toupper()?
Topic: File Handling
- iostream.h
- stdlib.h
- conio.h
- ctype.h ✓ Correct answer
-
Which mode is used to open a file or stream for extraction (input)?
Topic: File Handling
- ios::in ✓ Correct answer
- ios::out
- ios::ate
- ios::app
-
______ is the pointer which determines the position in a file from where the next read operation occurs.
Topic: File Handling
- put
- seek
- get ✓ Correct answer
- tell
-
Which of the following header file include string conversion functions?
Topic: File Handling
- string.h
- stdlib.h ✓ Correct answer
- ctype.h
- sconvert.h
-
Which header file is required to use file streams in a C++ program?
Topic: File Handling
- <string.h>
- <iostream.h>
- <fstream.h> ✓ Correct answer
- None of these
-
The _____ function is used to read a single character from a file.
Topic: File Handling
- put()
- getline()
- get() ✓ Correct answer
- None of these
-
If you open a file with ios::app mode, where will the data be written?
Topic: File Handling
- At the start
- At the end ✓ Correct answer
- Replaces everything
- None of these
-
What is the primary characteristic of sequential access files?
Topic: File Handling
- They are read and written in a sequence ✓ Correct answer
- They allow random jumping to any position
- They store data only in binary format
- None of these
-
How do you determine the actual data length of a file?
Topic: File Handling
- Using tellp() only
- Using seekp(0, ios::beg) and tellp()
- Using seekg(0, ios::end) and tellg() ✓ Correct answer
- None of these
-
To move 10 bytes forward from the beginning, which code is correct?
Topic: File Handling
- aFile.seekg(10L, ios::beg) ✓ Correct answer
- aFile.seekg(10L, ios::end)
- aFile.seekg(10L, ios::cur)
- None of these
-
What is the use of ios::trunc mode?
Topic: File Handling
- To open a file in input mode
- To open a file in output mode
- To truncate an existing file to half
- To truncate an existing file to zero ✓ Correct answer