1.
What is the meaning of the following declaration?
int(*p[5])();
Correct Answer
B. P is array of pointer to function
Explanation
The declaration "int(*p[5])();" means that p is an array of 5 pointers to functions that return an integer. Each element in the array can point to a different function that returns an integer.
2.
What is the output of this program?
#include
using namespace std;
int main()
{
int arr[] = {4, 5, 6, 7};
int *p = (arr + 1);
cout << *arr + 9;
return 0;
}
Correct Answer
C. 13
Explanation
The program declares an array `arr` of integers with values {4, 5, 6, 7}. It then declares a pointer `p` and assigns it the address of the second element of `arr` (arr + 1).
The line `cout
3.
. int main()
{
int row[20],i,sum=0;
int *p=row;
for(i=0;i<20;i++)
*(p+i)=1;
for(i=0;i<20;i+=sizeof(int))
sum+=*(p+i);
printf("sum=%d\n",sum);
}
Correct Answer
A. Sum=10
Explanation
The given code initializes an array 'row' with 20 elements and assigns the value 1 to each element using a pointer 'p'. Then, it calculates the sum of the elements in the array by iterating over the elements using pointer arithmetic. Since the size of an integer is typically 4 bytes, the loop increments the pointer by 4 in each iteration. Therefore, it only considers every 4th element in the array, resulting in a sum of 10.
4.
#include<stdio.h>
int main()
{
int a=10,b=10;
if(a==5)
b--;
printf("%d,%d",a,b--);
}
Correct Answer
C. A=5, b=9
Explanation
The if statement checks if the value of 'a' is equal to 5. Since 'a' is not equal to 5, the code inside the if statement is not executed. Therefore, the value of 'b' remains the same, which is 10. However, the value of 'b' is decremented by 1 after it is printed, resulting in the final value of 'b' being 9.
5.
Which is valid C expression?
Correct Answer
B. int my_num = 100000;
Explanation
The correct answer is "int my_num = 100000;". This is a valid C expression because it follows the syntax rules of C programming. The variable "my_num" is declared as an integer and assigned the value of 100000. The other options have syntax errors - the first option has a comma in the number which is not allowed, the third option has a space in the variable name which is not allowed, and the fourth option starts with a dollar sign which is not allowed.
6.
What is the use of Namespace?
Correct Answer
B. To structure a program into logical units
Explanation
The use of a namespace is to structure a program into logical units. Namespaces provide a way to organize code and prevent naming conflicts. They allow for better organization and management of code by grouping related classes, functions, and variables together. This helps improve code readability, maintainability, and reusability. By structuring a program into logical units using namespaces, it becomes easier to understand and navigate the codebase, making development and debugging more efficient.
7.
Which data structure type is NOT linear from the following?
Correct Answer
C. Binary Search Tree
Explanation
A binary search tree is a non-linear data structure as it does not follow a sequential order. It is a tree-like structure where each node has at most two children, a left child and a right child. The nodes are arranged in a specific order based on their values, with the left child having a smaller value and the right child having a larger value. This hierarchical structure allows for efficient searching and sorting operations. Unlike linear data structures such as doubly linked lists, 2D arrays, and queues, a binary search tree does not have a linear arrangement of elements.
8.
Which of the followings is/are pointer-to-member declarator?
Correct Answer
C. ::*
Explanation
The correct answer is "::*". This is because "::" is the scope resolution operator, and "*" is the pointer operator. When used together, "::*" is used to declare a pointer to a member of a class.
9.
What will happen in this code?
int a = 100, b = 200;
int *p = &a, *q = &b;
p = q;
Correct Answer
B. P now points to b
Explanation
In this code, two variables `a` and `b` are declared and assigned values of 100 and 200 respectively. Then, two pointers `p` and `q` are declared and assigned the addresses of `a` and `b` respectively. Finally, the value of `q` is assigned to `p`, which means `p` now points to `b`.
10.
What does the following declaration mean?
int (*ptr)[10];
Correct Answer
B. Ptr is a pointer to an array of 10 integers
Explanation
The declaration "int (*ptr)[10]" means that "ptr" is a pointer to an array of 10 integers. The parentheses around "*ptr" indicate that "ptr" is a pointer, and the "[10]" indicates that it is a pointer to an array of 10 integers.
11.
#include <stdio.h>
void main()
{
int x = 0;
if (x == 0)
printf("hi");
else
printf("how are u");
printf("hello");
}
Correct Answer
D. Hihello
Explanation
The correct answer is "hihello" because the variable x is initialized to 0, and the if statement checks if x is equal to 0. Since x is indeed equal to 0, the code inside the if statement is executed, which prints "hi". After that, the code continues to execute the next line, which prints "hello". So the output will be "hihello".
12.
Which of the following is not a valid variable name declaration?
Correct Answer
C. Int 3_a;
Explanation
The variable name declaration "int 3_a;" is not valid because it starts with a number, which is not allowed in variable names in most programming languages. Variable names should start with a letter or an underscore.
13.
#include <stdio.h>
void main()
{
int x = 4, y, z;
y = --x;
z = x--;
printf("%d%d%d", x, y, z);
}
Correct Answer
B. 2 3 3
Explanation
The code snippet initializes the variable x with the value 4. Then, the value of x is decremented by 1 using the pre-decrement operator --x and assigned to the variable y. So, y becomes 3. Next, the value of x is decremented by 1 using the post-decrement operator x-- and assigned to the variable z. So, z becomes 3. Finally, the printf statement prints the values of x, y, and z, which are 2, 3, and 3 respectively. Therefore, the correct answer is 2 3 3.
14.
What is the output of this program?
#include <iostream>
using namespace std;
enum colour {
green, red, blue, white, yellow, pink
};
int main()
{ cout << green<< red<< blue<< white<< yellow<< pink;
return 0;
}
Correct Answer
A. 012345
Explanation
The program defines an enumeration called "colour" with six values: green, red, blue, white, yellow, and pink. In the main function, it prints the values of the enumeration variables in sequence without any separators. Therefore, the output of the program will be the concatenation of the integer values of the enumeration variables: 012345.
15.
#include <stdio.h>
void main()
{
int a = 5, b = -7, c = 0, d;
d = ++a && ++b || ++c;
printf("\n%d%d%d%d", a, b, c, d);
}
Correct Answer
D. 6 -6 0 1
Explanation
The code snippet initializes variables a, b, and c with values 5, -7, and 0 respectively. The expression d = ++a && ++b || ++c is then evaluated. Since the && operator has higher precedence than the || operator, the expressions ++a and ++b are evaluated first. The value of a is incremented to 6 and b is incremented to -6. The result of the logical AND operation (6 && -6) is false (0). Since the result of the logical AND operation is false, the expression ++c is not evaluated. The value of d is assigned the value of the logical OR operation between the result of the logical AND operation and ++c, which is true (1). Therefore, the final values of a, b, c, and d are 6, -6, 0, and 1 respectively.
16.
#include <stdio.h>
int main()
{
float x = 'a';
printf("%f", x);
return 0;
}
Correct Answer
D. 97.000000
Explanation
The code snippet declares a variable 'x' of type float and assigns it the ASCII value of the character 'a'. When the program prints the value of 'x' using the '%f' format specifier, it converts the ASCII value of 'a' (which is 97) into a floating-point number and prints it as "97.000000".
17.
. Which one of the following is correct about the statements given below?
All function calls are resolved at compile-time in Procedure Oriented Programming.
All function calls are resolved at compile-time in OOPS.
Correct Answer
C. Only I is correct.
Explanation
In Procedure Oriented Programming, all function calls are resolved at compile-time. This means that the compiler determines the address of the function to be called during the compilation process. On the other hand, in Object-Oriented Programming (OOPS), function calls are resolved at runtime using dynamic binding or late binding. Therefore, only statement I is correct, stating that all function calls are resolved at compile-time in Procedure Oriented Programming.
18.
Which operator has highest precedence in * / % ?
Correct Answer
D. All have same precedence
Explanation
The operators * (multiplication), / (division), and % (modulus) all have the same precedence. This means that they are evaluated from left to right in the order they appear in an expression. Therefore, there is no operator that has a higher precedence than the others in this case.
19.
#include <stdio.h>
int main()
{
enum {ORANGE = 5, MANGO, BANANA = 4, PEACH};
printf("PEACH = %d\n", PEACH);
}
Correct Answer
C. PEACH = 5
Explanation
In the given code, an enumeration is defined with four constants: ORANGE = 5, MANGO = 6, BANANA = 4, and PEACH. Since PEACH is not explicitly assigned a value, it will be assigned the next available integer value, which is 5. Therefore, the output of the printf statement will be "PEACH = 5".
20.
The keyword ‘break’ cannot be simply used within _________
Correct Answer
B. If-else
Explanation
The keyword 'break' cannot be simply used within the if-else statement. The 'break' statement is used to exit a loop or switch statement. However, the if-else statement is not a loop or switch statement, but a conditional statement. Therefore, using 'break' within the if-else statement would result in a syntax error.
21.
#include <stdio.h>
struct student
{
char a[5];
};
void main()
{
struct student s[] = {"hi", "hey"};
printf("%c", s[0].a[1]);
}
Correct Answer
B. I
Explanation
The code snippet declares a structure named "student" with a character array "a" of size 5. In the main function, an array of "student" structures named "s" is declared and initialized with two string literals "hi" and "hey". The printf statement then prints the character at index 1 of the first element of the array "s", which is 'i'.
22.
Which value can we not assign to reference?
Correct Answer
D. null
Explanation
We cannot assign the value "null" to a reference. In programming, "null" represents the absence of a value or a non-existent object. References are used to point to objects or variables, and they must always refer to a valid memory location. Assigning "null" to a reference would mean that the reference does not point to any object or variable, which is not allowed.
23.
Identify the incorrect option.
Correct Answer
C. Enumerators are same as macros
Explanation
The given answer is incorrect because enumerators are not the same as macros. Enumerators are used to define named constants in C programming language, while macros are used to define code snippets that are replaced by the preprocessor before compilation. Macros can be used for various purposes, including defining constants, but they are not the same as enumerators.
24.
Which keyword is used to define the user defined data types?
Correct Answer
C. Typedef
Explanation
The keyword "typedef" is used to define user-defined data types in programming. It allows the programmer to create a new name for an existing data type, making the code more readable and easier to understand. By using "typedef", the programmer can create aliases for complex data types, such as structures or arrays, simplifying the code and making it more manageable.
25.
Printf(“%d”,printf(“tim”));
Correct Answer
B. Outputs tim3
Explanation
The given code snippet is using the printf function to print the string "tim" and then printing the return value of the inner printf function. The inner printf function will print "tim" and return the number of characters printed, which is 3. Therefore, the output of the code will be "tim3".
26.
Which operator is having the highest precedence?
Correct Answer
A. Postfix
Explanation
The postfix operator has the highest precedence among the given options. This means that it is evaluated first before any other operators. The postfix operator is used to increment or decrement a variable after it has been used in an expression. For example, if we have the expression "a++", the value of "a" will be incremented after it is used in the expression.
27.
Which is used to create a pure virtual function ?
Correct Answer
B. =0
Explanation
The "=0" syntax is used to create a pure virtual function in C++. A pure virtual function is a function that is declared in a base class but has no implementation. It is meant to be overridden by derived classes, forcing them to provide their own implementation. The "=0" syntax is added at the end of the function declaration to indicate that it is pure virtual.
28.
#include <stdio.h>
int fun(int arr[]) {
arr = arr+1;
printf("%d ", arr[0]);
}
int main(void) {
int arr[2] = {10, 20};
fun(arr);
printf("%d", arr[0]);
return 0;
}
Correct Answer
B. 20 10
Explanation
The program will output "20 10". The function fun() receives the array as a parameter, but when the pointer arr is incremented by 1, it points to the second element of the array. So, when arr[0] is printed inside the function, it prints the second element of the array, which is 20. However, the original array in the main() function remains unchanged, so when arr[0] is printed outside the function, it prints the first element of the array, which is 10.
29.
#include <stdio.h>
int main()
{
int x;
x = 5 > 8 ? 10 : 1 != 2 < 5 ? 20 : 30;
printf("Value of x:%d", x);
return 0;
}
Correct Answer
C. X=30
Explanation
The expression in the ternary operator is evaluated from left to right. The first condition, 5 > 8, is false, so the value after the colon, 30, is assigned to x. Therefore, the value of x is 30.
30.
#include <iostream>
using namespace std;
int main()
{
int x = 3, k;
while (x-- >= 0) {
printf("%d ", x);
}
return 0;
}
Correct Answer
B. 2 1 0 -1
Explanation
The code snippet initializes the variable x to 3 and enters a while loop. In each iteration of the loop, the value of x is printed and then decremented by 1. The loop continues as long as x is greater than or equal to 0.
In the first iteration, x is 3 and is printed. Then, x is decremented to 2. In the second iteration, x is 2 and is printed. Then, x is decremented to 1. In the third iteration, x is 1 and is printed. Then, x is decremented to 0. In the fourth iteration, x is 0 and is printed. Then, x is decremented to -1.
After the fourth iteration, the condition x >= 0 is no longer true, so the loop ends. Therefore, the output of the code is "2 1 0 -1".
31.
Consider the following definition in c programming language
struct node
{
int data;
struct node * next;
}
typedef struct node NODE;
NODE *ptr;
Which of the following c code is used to create new node?
Correct Answer
A. Ptr = (NODE*)malloc(sizeof(NODE));
Explanation
The correct answer is "ptr = (NODE*)malloc(sizeof(NODE));". This code is used to allocate memory for a new node of type NODE. The malloc function is used to dynamically allocate memory, and the sizeof operator is used to determine the size of the NODE structure. The result of the malloc function is cast to a pointer of type NODE* and assigned to the ptr variable, indicating that ptr now points to the newly allocated memory for the new node.
32.
#include <iostream>
using namespace std;
class Test
{
public:
Test() { cout << "Hello from Test() "; }
} a;
int main()
{
cout << "Main Started ";
return 0;
}
Correct Answer
C. Hello from Test() Main Started
Explanation
The correct answer is "Hello from Test() Main Started". This is because when the program is executed, the main function is called first. The line "cout
33.
#include <stdio.h>
int main()
{
int i = 25;
int* j;
int** k;
j = &i;
k = &j;
printf("%u %u %u ", k, *k, **k);
return 0;
}
Correct Answer
A. Address address value
Explanation
The correct answer is "address address value" because the code declares a variable `i` with the value 25. Then, it declares a pointer `j` and a double pointer `k`. `j` is assigned the address of `i`, and `k` is assigned the address of `j`. When printing, `k` represents the address of `j`, `*k` represents the value stored at the address of `j` (which is the address of `i`), and `**k` represents the value stored at the address of `i`, which is 25.
34.
Which of the following data type will throw an error on modulus operation(%)?
Correct Answer
D. float
Explanation
The modulus operator (%) is used to find the remainder of a division operation. It can only be used with integer data types. Since float is a floating-point data type, it cannot be used with the modulus operator and will throw an error.
35.
The sizeof(void) in a 32-bit C is_____
Correct Answer
B. 1
Explanation
In C programming language, the "void" keyword is used to indicate that a function does not return a value. The "sizeof" operator is used to determine the size of a data type in bytes. In a 32-bit C system, the size of "void" is typically 1 byte. This is because "void" does not have any specific size or memory representation, but it is usually assigned the smallest possible size of 1 byte. Therefore, the correct answer is 1.
36.
What is the output of the following code?
#include <stdio.h>
int main()
{
int a = 1;
switch (a)
{
case a:
printf("Case A ");
default:
printf("Default");
}
}
Correct Answer
D. Compile time error
Explanation
The code will result in a compile-time error because the value of the case statement in the switch statement must be a constant expression. In this case, the value of 'a' is not a constant expression as it is a variable.
37.
#include <iostream>
using namespace std;
int main()
{
int i;
for (i=0; i<3; i++);
cout << "hello!" <<i;
return 0;
}
Correct Answer
D. Hello!3
Explanation
The correct answer is "hello!3" because the for loop runs 3 times, incrementing the value of i each time. After the loop, the value of i is 3, so when it is printed out with the "hello!" string, it becomes "hello!3".
38.
#include<iostream>
using namespace std;
int x=20;
int main()
{
int x = 10;
cout << "Value of global x is " << ::x << endl;
return 0;
}
Correct Answer
C. 20
Explanation
The correct answer is 20 because the global variable x has a value of 20, which is printed using the scope resolution operator (::x) in the cout statement. The local variable x inside the main function is not used or printed, so it does not affect the output.
39.
What is the output of the following code?
#include <iostream>
using namespace std;
int main ( )
{
static double i;
i = 20;
cout << sizeof(i);
return 0;
}
Correct Answer
C. 8
Explanation
The output of the code is 8. The variable "i" is declared as a static double, which means it has a size of 8 bytes in memory. The sizeof() function is used to determine the size of the variable, and it returns the size in bytes. Therefore, when we print the result of sizeof(i), it will output 8.
40.
What is the output of the following program?
#include <iostream>
using namespace std;
int main()
{
int num1 = 10;
float num2 = 20;
cout << sizeof(num1 + num2);
return 0;
}
Correct Answer
B. 4
Explanation
The output of the program is 4. The sizeof() function is used to determine the size in bytes of a variable or data type. In this case, num1 and num2 are added together, resulting in a float value. The sizeof() function then returns the size in bytes of this float value, which is 4 bytes.
41.
Struct stock
{ int scale;
char code[10];
} S={11,“food”};
int main()
{
printf(“%d”,scale);
}
Correct Answer
B. 11
Explanation
The correct answer is 11. In the given code, a struct named "stock" is defined with two members: an integer "scale" and a character array "code". An instance of this struct named "S" is declared and initialized with the values 11 and "food" respectively. In the main function, the value of the "scale" member of the "S" instance is printed using the printf function. Since "scale" is a member of the struct and not a separate variable, it should be accessed using the dot operator (S.scale) instead of just "scale". Therefore, the correct answer is 11.
42.
- #include <iostream>
using namespace std;
int main()
{
int a = 5, b = 10, c = 15;
int *arr[ ] = {&a, &b, &c};
cout << arr[1];
return 0;
}
Correct Answer
D. It will return some random number
Explanation
The given code declares an array of integer pointers called "arr" and initializes it with the addresses of variables a, b, and c. When arr[1] is printed, it will return the value stored at the memory address pointed to by arr[1], which is the address of variable b. Therefore, the output will be the value of variable b, which is 10.
43.
Which of the following type of class allows only one object of it to be created?
Correct Answer
C. Singleton class
Explanation
A singleton class allows only one object of it to be created. This is achieved by making the constructor of the class private, so that it cannot be accessed from outside the class. The class provides a static method that returns the instance of the class, and this method is responsible for creating the object if it doesn't exist already. This ensures that only one instance of the class can be created and accessed throughout the program.
44.
Can we typecast void into int?
Correct Answer
A. Yes
Explanation
Yes, we can typecast void into int. Typecasting is a way to convert one data type into another. However, since void represents the absence of a type, it cannot hold any value. So, when we typecast void into int, it will result in an undefined or garbage value.
45.
What is the type of variable ‘b’ and ‘d’ in the below snippet?
int a[], b;
int []c, d;
Correct Answer
C. ‘b’ is int variable; ‘d’ is int array
Explanation
The variable 'b' is declared as an int variable, while the variable 'd' is declared as an int array.
46.
BOSS is developed by ________
Correct Answer
B. C-DAC
Explanation
BOSS (Bharat Operating System Solutions) is an operating system developed by C-DAC (Centre for Development of Advanced Computing). C-DAC is an Indian research and development organization that specializes in the design and development of advanced computing technologies. They have expertise in areas such as high-performance computing, software development, and networking. C-DAC's involvement in the development of BOSS makes them the correct answer for this question.
47.
What is size of generic pointer in C++ (in 32-bit platform) ?
Correct Answer
B. 4
Explanation
In a 32-bit platform, the size of a generic pointer in C++ is 4 bytes. This is because a generic pointer is used to store memory addresses, and in a 32-bit platform, memory addresses are typically represented using 32 bits or 4 bytes.
48.
What will be the output of the following code?
int a=36,b=9;
printf(“%d”,a>>a/b-2);
Correct Answer
A. 9
Explanation
The code first performs the division operation `a/b`, which results in 4. Then, it performs the right shift operation `a>>4`, which shifts the bits of 36 four positions to the right, resulting in 2. Finally, it subtracts 2 from 2, resulting in 0. The `printf` statement then outputs the value 0.
49.
What will be the output of the following code?
main()
{
int x=15;
printf(“\n%d%d%d”,x!=15,x=20,x<30);
}
Correct Answer
C. 1 20 1
Explanation
The output of the code will be "1 20 1". This is because the code uses the printf function to print three values: x!=15, x=20, and x
50.
Which reference modifier is used to define reference variable?
Correct Answer
A. &
Explanation
The reference modifier "&" is used to define a reference variable.