1.
Identify the loop construct:
Correct Answer
C. While
Explanation
The correct answer is "while" because it is a loop construct that allows a block of code to be repeatedly executed as long as a specified condition is true. The "while" loop first checks the condition, and if it is true, the code inside the loop is executed. This process continues until the condition becomes false, at which point the loop is exited.
2.
Which of the following is not a storage class?
Correct Answer
D. Define
Explanation
The storage class "define" is not a valid storage class in programming languages. The options "external," "automatic," and "register" are all valid storage classes that define how variables are stored and accessed in memory. However, "define" is not a recognized storage class and does not have any specific meaning in this context.
3.
Which of the following is a correct way of defining a symbolic constant pie in C?
Correct Answer
B. #define pie 22/7
Explanation
This is the correct way of defining a symbolic constant pie in C because it uses the correct syntax for the #define directive, which is followed by the name of the constant (pie in this case) and its corresponding value (22/7). The value is not assigned using the = symbol, but rather by leaving a space between the constant name and its value.
4.
The minimum number of times the for loop is executed is:
Correct Answer
A. 0
Explanation
The minimum number of times the for loop is executed is 0 because if the loop's condition is not initially satisfied, the loop will not execute at all.
5.
In switch statement:
Correct Answer
C. Default case, if used, can be placed anywhere
Explanation
In a switch statement, the default case is optional and can be placed anywhere within the switch block. It does not have to be the last case. The default case is executed when none of the other cases match the value being evaluated. It provides a fallback option for handling unexpected or unhandled values. However, it is good practice to place the default case at the end of the switch block to make the code more readable and to follow common conventions.
6.
How many while statements are possible in do... While loop?
Correct Answer
C. Any number
Explanation
A do...while loop is a type of loop where the code block is executed at least once, and then the condition is checked. If the condition is true, the code block is executed again. This loop will continue until the condition becomes false. Therefore, any number of while statements are possible in a do...while loop, as long as the condition is true.
7.
The storage area for register variables.
Correct Answer
C. Processor registers
Explanation
Processor registers are a small set of high-speed memory locations within the processor itself. They are used to store data that is frequently accessed by the processor, such as variables and intermediate results during calculations. Register variables are variables that are stored in processor registers instead of main memory. Storing variables in registers can improve performance because accessing data from registers is much faster than accessing data from memory. Therefore, processor registers are the most suitable storage area for register variables.
8.
Which of the following statements is false?
Correct Answer
D. The initialization part of a for statement cannot have more than one initialization
Explanation
The initialization part of a for statement can have more than one initialization. In a for statement, the initialization part allows multiple variables to be initialized and can include multiple expressions separated by commas. Therefore, the statement "The initialization part of a for statement cannot have more than one initialization" is false.
9.
Consider the segment
If(1) printf(“yes”);
else printf(“no”);
what will be the output
Correct Answer
C. Yes
Explanation
The given segment is an if-else statement. If the condition (1) is true, then the code inside the if block will execute, which is to print "yes". Since the condition is 1, which is considered true in C programming, the output will be "yes".
10.
The global variable can be declared:
Correct Answer
C. Before main
Explanation
Global variables are variables that can be accessed and used throughout the entire program. They are typically declared before the main function because they need to be accessible to all other functions and blocks within the program. Declaring the global variable before main ensures that it is available and can be used by any function or block within the program.
11.
Which of the following is not correct?
Correct Answer
A. While loop is executed atleast once
Explanation
The statement "while loop is executed at least once" is not correct. In a while loop, the condition is checked before the loop body is executed. If the condition is false initially, the loop body will not be executed at all. Therefore, it is possible for a while loop to not be executed at least once.
12.
Printf (“\ “ well done\” ”); what will be the output of this statement?
Correct Answer
C. “ well done”
Explanation
The given statement will output " well done" (with a space before and after). This is because the printf function is used to print the string " well done" (including the space characters) to the console. The backslashes before and after the double quotes are escape characters, which are used to include special characters within the string. In this case, the backslashes are used to include the double quotes within the string.
13.
What is the output of the following program?
main()
{static int y;
printf (“%d\n”, y);
}
Correct Answer
A. 0
Explanation
The program declares a static integer variable "y" inside the main function. Since static variables are initialized to zero by default, the value of "y" is 0. The program then prints the value of "y" using the printf function. Therefore, the output of the program is 0.
14.
The number of elements in array declaration:
Correct Answer
D. Requires to be specified
Explanation
The correct answer is "requires to be specified". In array declaration, the number of elements needs to be specified so that the compiler can allocate the appropriate amount of memory for the array. If the number of elements is not specified, the compiler will not know how much memory to allocate, resulting in a compilation error.
15.
In C every variable has:
Correct Answer
B. A type, name, value and size
Explanation
In C, every variable has a type, name, value, and size. The type determines the kind of data that the variable can hold, such as integer, character, or floating-point. The name is used to identify the variable and access its value. The value is the actual data stored in the variable. The size represents the amount of memory allocated for the variable, which depends on its type.
16.
All the elements in the array must be:
Correct Answer
A. Defined
Explanation
The correct answer is "defined" because in order for an element to be used in an array, it must be defined, meaning that it has been declared and given a specific type. Initialization is not necessary for an element to be considered defined in an array.
17.
How many bytes will be allotted for the declaration int num[4] [3]?
Correct Answer
B. 24 bytes
Explanation
The declaration int num[4][3] creates a 2-dimensional array with 4 rows and 3 columns. Since an int data type typically requires 4 bytes of memory, each element in the array will take up 4 bytes. Therefore, the total memory allotted for the array will be 4 bytes * 4 rows * 3 columns, which equals 24 bytes.
18.
If statement is a —————statement.
Correct Answer
B. Two way decision
Explanation
A two-way decision statement is a type of statement that allows the program to make a choice between two possible paths based on a condition. It typically uses the keywords "if" and "else" to specify the conditions and the corresponding actions to be taken. This type of statement is commonly used when there are two alternative courses of action depending on the evaluation of a condition.
19.
The total memory required for an array:
Correct Answer
C. Sizeof (datatype) * sizeof array
Explanation
The correct answer is sizeof (datatype) * sizeof array. This is because the total memory required for an array is calculated by multiplying the size of each element (datatype) by the total number of elements in the array (sizeof array).
20.
Int table [2][3] ={{0}, {0}} in this statement.
Correct Answer(s)
B. Only first row elements are initialized to zero
D. All the array elements are initialized to zero
Explanation
The given statement initializes a 2-dimensional array called "table" with 2 rows and 3 columns. The initialization values are given as {{0}, {0}}, which means that the first row elements are explicitly initialized to zero. However, since the second row is not specified, it is assumed to be initialized to zero as well. Therefore, all the array elements are initialized to zero.
21.
The statement that prints out the character set from A-Z is, where a is an integer variable.
Correct Answer
D. For(a=’A’ a
Explanation
The correct answer is "for(a=’A’ a". This is because 'A' is the ASCII value of the character 'A', and by incrementing the variable 'a' in each iteration of the loop, it will print out the character set from A-Z.
22.
The amount of storage required for holding elements of the array depends on:
Correct Answer
B. Datatype and size
Explanation
The amount of storage required for holding elements of the array depends on the data type and size. Different data types require different amounts of memory to store their values, and the size of the array determines how many elements can be stored. Therefore, both the data type and size of the array are factors that determine the amount of storage required.
23.
If we don’t initialize a static array, what will be the elements set to:
Correct Answer
C. 0
Explanation
If we don't initialize a static array, the elements will be set to 0.
24.
What is wrong with the following program?
main() { char m1[9]= “message1”; char m2[9]=“message2”; m2=m1;
printf(“msg is %s”,m2); }
Correct Answer
B. Array is not a left value and so cannot be assigned to
Explanation
In the given program, the variable "m2" is declared as an array of characters. However, arrays are not assignable in C, meaning that we cannot directly assign one array to another. This is because arrays decay into pointers, and pointers cannot be assigned to. Therefore, the line "m2=m1;" is incorrect and will result in a compilation error.
25.
Array subscripts in ‘C’ always start at:
Correct Answer
A. 0
Explanation
In the C programming language, array subscripts always start at 0. This means that the first element in an array is accessed using the subscript 0, the second element with subscript 1, and so on. This convention is followed in C and many other programming languages, and it is important to keep in mind when working with arrays to avoid off-by-one errors.
26.
The maximum number of dimension an array can have in C language is:
Correct Answer
C. Compiler dependent
Explanation
In C language, the maximum number of dimensions an array can have is compiler dependent. This means that the maximum number of dimensions allowed for an array can vary depending on the compiler being used. Different compilers may have different limits on the number of dimensions allowed for an array. Therefore, the maximum number of dimensions an array can have in C language cannot be determined universally and is determined by the specific compiler being used.
27.
What is the result of the expression ( 10/3 )*3+5%3?
Correct Answer
B. 11
Explanation
The expression (10/3) evaluates to 3.3333, and when multiplied by 3, it becomes 9.9999. The expression 5%3 evaluates to 2, as it gives the remainder when 5 is divided by 3. Adding these two results together, we get 9.9999 + 2 = 11. Therefore, the result of the expression is 11.
28.
Output of the below program
#include<stdio.h>
main()
{int a,b=0;
int c[10]={1,2,3,4,5,6,7,8,9,0 };
for(a=0;a<10;++a)
b+=c[a];
printf(“%d”,b);
}
Correct Answer
C. 45
Explanation
The given program initializes an array 'c' with 10 elements and assigns values from 1 to 10. It then uses a for loop to iterate through each element of the array and adds it to the variable 'b'. Finally, it prints the value of 'b', which is 45. Therefore, the output of the program is 45.
29.
Consider the array definition
int num [10] = { 3 ,3 ,3 };
pick the correct answers
Correct Answer
D. The value of num[2] is 3
Explanation
The given array definition initializes an array named "num" with a size of 10 and assigns the values 3, 3, and 3 to the first three elements of the array. Since arrays in most programming languages are zero-indexed, the element at index 2 (num[2]) will have a value of 3.
30.
Which of the follwing is a string?
Correct Answer
B. “abcd”
Explanation
The correct answer is "abcd" because it is enclosed within double quotation marks, which is the standard way of representing a string in many programming languages. The other options either do not have any quotation marks or have mismatched quotation marks, making them invalid representations of a string.
31.
Give the output of the following program:
#include < stdio.h >
main()
{int I=1;
while (I < 5)
{printf(“%d”, I);
}}
/* End of Main */
Correct Answer
C. Infinite loop
Explanation
The program contains a while loop that will continue to execute as long as the condition "I < 5" is true. However, there is no increment or change in the value of I within the loop, so the condition will always remain true. Therefore, the loop will continue indefinitely, resulting in an infinite loop. This means that the program will keep printing the value of I as 1 repeatedly without any end.
32.
How would you copy the name “Hello” to a character array (i.e. string) declared as char str[10];
Correct Answer
A. Strcpy( str, “Hello” );
Explanation
The correct answer is strcpy( str, “Hello” ). This function is used to copy a string from one location to another. In this case, it will copy the string "Hello" to the character array "str". The other options are incorrect. strcat() is used to concatenate two strings, printf() is used to print a formatted string, and str = "Hello" is invalid syntax as you cannot assign a string directly to a character array.
33.
count=0;
for ( I=0;I<=10; I++)
{if(I%2==0)
count++;
}printf(“%d”, count);
Pick out the correct value for count
Correct Answer
A. 6
Explanation
The given code initializes a variable count to 0. Then, it enters a for loop where it iterates from 0 to 10. Inside the loop, it checks if the current value of I is divisible by 2 (i.e., even). If it is, it increments the count variable by 1. Finally, it prints the value of count. Since there are 6 even numbers (0, 2, 4, 6, 8, 10) between 0 and 10, the correct value for count is 6.
34.
What will happen if you try to put so many values into an array during the initialization such that its size is exceeded?
Correct Answer
B. Possible system malfunction
Explanation
If you try to put so many values into an array during initialization that exceeds its size, it can lead to a possible system malfunction. This is because the array is allocated a fixed amount of memory during initialization, and if you try to store more values than the allocated memory can hold, it can cause memory corruption and potentially crash the system.
35.
Compute the result of the following expression in ‘C’. A=3*4/5+10/5+8-1+7/8
Correct Answer
A. 11
Explanation
The given expression is evaluated according to the order of operations in C. First, the multiplication and division operations are performed from left to right. So, 3 multiplied by 4 is 12, and 12 divided by 5 is 2.4. Next, the addition and subtraction operations are performed from left to right. So, 2.4 plus 2 is 4.4, and 4.4 minus 1 is 3.4. Finally, the division operation is performed, so 7 divided by 8 is 0.875. Adding 0.875 to 3.4 gives the final result of 4.275, which is rounded down to 4. Therefore, the correct answer is 11.
36.
Which of the following statements would read a single character from the keyboard and place the result in a character variable ‘ch’ defined as: char ch;
Correct Answer
A. Ch = getch( );
Explanation
The correct answer is `ch = getch();` because the `getch()` function reads a single character from the keyboard and returns it, which is then assigned to the character variable `ch`. This statement ensures that the character from the keyboard is stored in the variable `ch`.
37.
What is the output of the following module
sum=0; I=0;
do{ sum+=I;
I++;
}while(I<=5);
printf(“%d”, sum);
Correct Answer
C. 15
Explanation
The given code initializes the variables sum and I to 0. It then enters a do-while loop where it adds the value of I to the sum and increments I by 1. This process continues until I becomes greater than 5. After the loop ends, the value of sum is printed using the printf statement. Since the loop iterates 5 times and adds the values of I (1+2+3+4+5), the output will be 15.
38.
The value within the [] brackets in an array declaration specifies
Correct Answer
D. Size of an array
Explanation
The value within the [] brackets in an array declaration specifies the size of the array. This value indicates the number of elements that can be stored in the array. It determines the amount of memory allocated for the array and helps in accessing the elements of the array using their respective indices.
39.
Dynamic memory allocation in array results in:
Correct Answer
D. Allocation of memory at runtime
Explanation
Dynamic memory allocation in an array refers to the process of allocating memory for the array elements during program execution, specifically at runtime. This means that the memory for the array is allocated dynamically based on the program's needs, allowing for flexibility in the size of the array. Unlike static memory allocation, which occurs at compile time and has a fixed size, dynamic memory allocation allows for the creation of arrays whose size can be determined and modified during program execution.
40.
main()
{ char name[5];
scanf(“%s”,name);
printf(“%s”, name);
}if Program is the given as input, what will be the o/p of the program;
Correct Answer
B. Prog
Explanation
The program declares a character array named "name" with a size of 5. It then uses the scanf function to read input from the user and store it in the "name" array. However, since the size of the array is only 5, it can only store up to 4 characters plus the null terminator. Therefore, when the input "Program" is given, only the first 4 characters "Prog" will be stored in the array. Finally, the printf function is used to print the contents of the "name" array, which will output "Prog".