1.
Which is more memory efficient ?
Correct Answer
B. Union
Explanation
A union is more memory efficient compared to a structure because it allows different variables to share the same memory space. In a structure, each variable has its own memory space, leading to potential wastage of memory. However, in a union, all variables share the same memory space, which reduces memory consumption. This is particularly useful when only one variable is accessed at a time, as it allows for efficient memory utilization.
2.
How we can define member function outside the class ?
Correct Answer
D. Using scope resolution
Explanation
Member functions in C++ can be defined outside the class using the scope resolution operator (::). This allows the definition of the function to be separate from the class declaration, providing better organization and readability of the code. By using the scope resolution operator, the function is associated with the specific class and can access its private members.
3.
Which of the following operations can be performed on the file "NOTES.TXT" using the below code?FILE *fp;
fp = fopen("NOTES.TXT", "r+");
Correct Answer
D. Read and Write
Explanation
The code snippet opens the file "NOTES.TXT" with the mode "r+" which allows both reading and writing operations on the file. Therefore, the operations that can be performed on the file using this code are reading and writing.
4.
Which among the following is NOT a logical or relational operator?
Correct Answer
B. =
Explanation
The operator "=" is not a logical or relational operator. It is the assignment operator used to assign a value to a variable. Logical and relational operators are used to compare values or check conditions, such as "!=" (not equal to), "||" (logical OR), and "==" (equal to).
5.
Which of the following concepts means determining at runtime what method to invoke?
Correct Answer
C. Dynamic binding
Explanation
Dynamic binding refers to the process of determining at runtime which method to invoke. It allows the program to select the appropriate method based on the actual type of the object, rather than the declared type. This enables polymorphism, where different objects can respond differently to the same method call. Dynamic binding is an essential feature of object-oriented programming languages, as it allows for flexibility and extensibility in the code.
6.
To print out a and b given below, which of the following printf() statement will you use?#include<stdio.h>
float a=3.14;
double b=3.14;
Correct Answer
A. Printf("%f %lf", a, b);
Explanation
The correct answer is printf("%f %lf", a, b) because the variable "a" is a float and the variable "b" is a double. The format specifier "%f" is used to print float values and "%lf" is used to print double values.
7.
A .............. is an alias or synonym for another variable.
Correct Answer
A. reference
Explanation
A reference is an alias or synonym for another variable. In other words, it is a way to refer to the same memory location or data as another variable, but with a different name. By using a reference, we can access and manipulate the value of the original variable through the reference variable. This can be useful in situations where we want to have multiple names for the same data or when we want to pass variables by reference to functions.
8.
What will be the output of the program ?#include<stdio.h>
int main()
{
int k=1;
printf("%d == 1 is" "%s\n", k, k==1?"TRUE":"FALSE");
return 0;
}
Correct Answer
B. 1 == 1 is TRUE
Explanation
The program will output "1 == 1 is TRUE". This is because the variable "k" is initialized to 1, and the expression "k==1" evaluates to true. Therefore, the program will print "TRUE" as the output.
9.
Which of the following concept of oops allows compiler to insert arguments in a function call if it is not specified?
Correct Answer
C. Default arguments
Explanation
Default arguments in object-oriented programming allow the compiler to automatically insert arguments in a function call if they are not specified by the programmer. This feature is useful when a function has parameters that have default values assigned to them. If the programmer does not provide a value for a particular parameter, the compiler will automatically use the default value defined in the function declaration. This allows for more flexibility and convenience when calling functions, as it reduces the need for explicitly specifying all arguments in every function call.
10.
Cout is a/an __________ .
Correct Answer
C. Object
Explanation
The correct answer is "object" because "cout" is an object of the "ostream" class in C++. It is used to display output on the console.
11.
What are mandatory parts in function declaration?
Correct Answer
A. Return type,function name
Explanation
The mandatory parts in a function declaration are the return type and the function name. These two components are essential in defining a function in any programming language. The return type specifies the type of value that the function will return, while the function name is used to identify and call the function in the code. The parameters, on the other hand, are optional and may or may not be included in the function declaration depending on the requirements of the program.
12.
If a is an integer variable, a=7/3; will return a value
Correct Answer
D. 2
Explanation
The expression "a=7/3" assigns the value of the division of 7 by 3 to the variable "a". In integer division, any decimal part is truncated, so the result is 2. Therefore, the correct answer is 2.
13.
Which of the following are available only in the class hierarchy chain?
Correct Answer
C. Protected data members
Explanation
Protected data members are available only in the class hierarchy chain. This means that they can be accessed by the derived classes that inherit from the base class, but not by objects of the base class or objects of other unrelated classes. Protected data members provide a level of encapsulation and allow derived classes to have access to certain data that is not accessible to the outside world.
14.
What happens when a class with parameterized constructors and having no default constructor is used in a program and we create an object that needs a zero-argument constructor?
Correct Answer
A. Compile-time error.
Explanation
When a class with parameterized constructors and no default constructor is used in a program, it means that the class requires specific arguments to be passed during object creation. If we try to create an object of this class without providing the required arguments, a compile-time error will occur. This is because the compiler cannot find a suitable constructor to create the object, resulting in a compile-time error.
15.
Can you combine the following two statements into one?char *p;
p = (char*) malloc(100);
Correct Answer
C. Char *p = (char*)malloc(100);
Explanation
The correct answer is "char *p = (char*)malloc(100)". This is because it correctly combines the two statements into one. The first statement declares a pointer variable "p" of type char. The second statement allocates memory of size 100 using malloc and assigns the address of the allocated memory to the pointer variable "p".
16.
Which is not a storage class?
Correct Answer
B. Struct
Explanation
The storage classes in C programming language are auto, register, static, and extern. Struct is not a storage class; it is a keyword used to define a user-defined data type that groups different types of variables together.
17.
What does the client module import?
Correct Answer
C. Interface
Explanation
The client module imports the interface.
18.
How many types of constructor are there in C++?
Correct Answer
C. 3
Explanation
In C++, there are three types of constructors. The first type is the default constructor, which is automatically called when an object is created without any arguments. The second type is the parameterized constructor, which allows us to initialize the object with specific values. The third type is the copy constructor, which is used to create a new object by copying the values of an existing object. Therefore, the correct answer is 3.
19.
Which of the following is the correct order if calling functions in the below code?a = f1(23, 14) * f2(12/4) + f3();
Correct Answer
C. Order may vary from compiler to compiler
Explanation
The correct answer is "Order may vary from compiler to compiler." In this code, the functions f1, f2, and f3 are being called in an expression to calculate the value of variable a. The order in which these functions are executed can vary depending on the compiler being used. Different compilers may have different rules or optimizations that determine the order of function execution. Therefore, the order of calling functions cannot be determined definitively and may vary.
20.
#include is called
Correct Answer
A. Preprocessor directive
Explanation
The given correct answer is "Preprocessor directive" because the "#include" statement is a preprocessor directive in C and C++ programming languages. Preprocessor directives are instructions that are processed by the preprocessor before the compilation of the code. The "#include" directive is used to include header files in the code, allowing the use of functions and definitions from those files in the program. Therefore, the statement "#include is called" is referring to the preprocessor directive that includes external files in the code.
21.
What is output for the following code:#include <stdio.h>int main(){static int a = 3;printf(“%d”, a --);return 0;}
Correct Answer
D. 3
Explanation
The code snippet declares a static integer variable "a" with an initial value of 3. The printf statement prints the value of "a" and then decrements it by 1. Since the decrement operator "--" is placed after the variable, the value of "a" is printed before it is decremented. Therefore, the output of the code will be 3.
22.
What is the output of this C code? void main() { int x = 4.3 % 2; printf("Value of x is %d", x); }
Correct Answer
D. Compile time error
Explanation
The code will result in a compile time error. In C, the modulus operator (%) can only be used with integer operands. In this code, the variable x is declared as an integer, but the value 4.3 is a floating-point number. Therefore, the code will not compile because the modulus operator cannot be used with a floating-point operand.
23.
Which of the following statement is correct?
Correct Answer
C. Strcmp(s1, s2) returns 0 if s1==s2
Explanation
The correct statement is that strcmp(s1, s2) returns 0 if s1 is equal to s2. This is because strcmp() is a function in C programming language that compares two strings. It returns a value less than 0 if the first string (s1) is greater than the second string (s2), a value greater than 0 if the first string is less than the second string, and 0 if the strings are equal. Therefore, the correct answer is that strcmp(s1, s2) returns 0 if s1 is equal to s2.
24.
Relational operators cannot be used on:
Correct Answer
A. structure
Explanation
Relational operators, such as greater than (>), less than (
25.
Which of the following statement is correct?
Correct Answer
B. A reference is stored on stack.
Explanation
A reference is stored on the stack because when a variable is declared and assigned a value, the reference to that variable is stored on the stack. The stack is a region of memory that is used for local variables and function calls. When a function is called, the variables and their references are pushed onto the stack, and when the function returns, they are popped off the stack. Therefore, a reference is stored on the stack.
26.
Input/output function prototypes and macros are defined in which header file?
Correct Answer
C. Stdio.h
Explanation
The correct answer is stdio.h. This header file contains the necessary function prototypes and macros for input/output operations in C programming. It includes functions like printf() and scanf() that are used for displaying output and taking input respectively.
27.
Which is the only function all C programs must contain?
Correct Answer
C. Main()
Explanation
In C programming, the main() function is the entry point of any program. It is the function that is automatically called when the program starts executing. Therefore, all C programs must contain a main() function. This function is responsible for executing the code and controlling the flow of the program. It typically contains the instructions and logic that need to be executed by the program.
28.
For 16-bit compiler allowable range for integer constants is ________?
Correct Answer
D. -32768 to 32767
Explanation
The correct answer is -32768 to 32767. This is because a 16-bit compiler can represent integers using 16 bits, which allows for a total of 2^16 = 65536 different values. However, one bit is used to represent the sign of the integer, leaving 15 bits to represent the magnitude. With 15 bits, the range of representable values is -2^15 to 2^15 - 1, which is equivalent to -32768 to 32767.
29.
What is the size of an int data type?
Correct Answer
C. Depends on the system/compiler
Explanation
The size of an int data type depends on the system or compiler being used. Different systems or compilers may allocate different amounts of memory for an int variable. Therefore, the size cannot be determined without considering the specific system or compiler in use.
30.
What will be printed for the below statement?#include<stdio.h>
main()
{
printf("%d",strcmp("strcmp()","strcmp()"));
}
Correct Answer
A. 0
Explanation
The code is using the strcmp() function to compare two strings "strcmp()" and "strcmp()". The strcmp() function returns 0 if the two strings are equal. Therefore, the printf() statement will print 0.