1.
Identify the loop construct:
Correct Answer
C. While
Explanation
The correct answer is "while". The while loop is a control flow statement that allows a block of code to be executed repeatedly as long as a given condition is true. It is used when the number of iterations is not known beforehand and the loop needs to continue until a certain condition is met. The code block inside the while loop will keep executing as long as the condition remains true.
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 C programming. The correct storage classes in C are "external", "automatic", and "register". The "define" option is not a storage class but is used for defining constants in the C preprocessor.
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
The correct way of defining a symbolic constant pie in C is by using the #define directive followed by the name of the constant (in this case "pie") and its value (in this case 22/7). The correct answer, #define pie 22/7, follows this format and correctly defines the symbolic constant "pie" with the value of 22/7.
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 condition is initially false, the loop will not be executed at all.
5.
In switch statement
Correct Answer
C. Default case, if used, can be placed anywhere
Explanation
The correct answer is that the default case, if used, can be placed anywhere in a switch statement. Unlike other cases, which are executed when a specific condition is met, the default case is executed when none of the other cases match the given condition. It acts as a catch-all option, ensuring that there is always a fallback option in case none of the other cases are satisfied. The placement of the default case within the switch statement does not affect its functionality; it can be placed at the beginning, middle, or end of the switch statement.
6.
How many while statements are possible in do.... While loop?
Correct Answer
C. Any number
Explanation
In a do...while loop, the condition is checked after the loop body is executed. This means that the loop will always execute at least once. The number of while statements in a do...while loop can be any number because the loop will continue to execute as long as the specified condition is true. Therefore, there is no limit to the number of while statements that can be used in a do...while loop.
7.
The storage area for register variables
Correct Answer
C. Processor registers
Explanation
The correct answer is processor registers because register variables are stored in the processor registers. Processor registers are small, fast memory locations within the CPU that can be accessed quickly by the processor. They are used to store data that is frequently accessed by the CPU, such as variables that are frequently used in a program. Storing register variables in processor registers allows for faster access and execution of the program.
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 for multiple variables to be initialized or multiple expressions to be evaluated. This allows for more flexibility in initializing variables before the loop begins.
9.
Consider the segment
If(1) printf(“yes”);
else printf(“no”);
what will be the output
Correct Answer
C. Yes
Explanation
The correct answer is "yes" because the condition in the if statement is 1, which is considered as true. Therefore, the code inside the if block will be executed, and it will print "yes" to the console.
10.
The global variable can be declared
Correct Answer
C. Before main
Explanation
Global variables can be declared before the main function in C programming. This means that the variable can be defined outside of any function, including main, and can be accessed and used by any function within the program. Declaring a global variable before main ensures that it is available for use throughout the entire program, rather than being limited to a specific function or block.
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 is executed. If the condition is false initially, the loop will not be executed at all. Therefore, it is not guaranteed that a while loop will be executed at least once.
12.
printf (“\ “ well done\” ”); what will be the output of this statement
Correct Answer
C. “ well done”
Explanation
The correct answer is " well done". The statement printf("\ " well done\ " "); will output the string " well done" with a space before and after the word. The backslashes before the double quotes are escape characters that allow the double quotes to be included in the printed 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" but does not initialize it, so its default value is 0. The printf statement then prints the value of "y", which is 0, as the output.
14.
The number of elements in array declaration
Correct Answer
D. Requires to be specified
Explanation
In array declaration, the size of the array needs to be specified. This means that the programmer needs to explicitly mention the number of elements that the array can hold. Unlike some programming languages, where the size of the array can be determined dynamically based on the largest index used in the program, in this case, the size must be explicitly mentioned.
15.
In C every variable has
Correct Answer
B. A type, name, value and size
Explanation
In C, every variable has a type, which determines the kind of data it can store (such as integer, float, or character), a name to identify the variable, a value that represents the data stored in the variable, and a size that determines the amount of memory allocated for the variable. This information is essential for the compiler to correctly interpret and manipulate the variable in the program.
16.
All the elements in the array must be
Correct Answer
A. Defined
Explanation
The correct answer is "defined" because when all the elements in an array are defined, it means that they have been declared and assigned a value. This is different from being initialized, which means that the elements have been assigned a default value, or being initialized and defined, which means that the elements have been assigned a specific value. Therefore, in order for the array to be considered complete, all its elements must be defined.
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. Each element of the array is an integer, which typically requires 4 bytes of memory. Since there are 12 elements in total (4 rows * 3 columns), the total memory allocated for this array would be 12 * 4 = 48 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 for two possible outcomes based on a condition. It typically uses an "if-else" structure, where one block of code is executed if the condition is true, and another block of code is executed if the condition is false. This type of statement is useful when there are two distinct paths that the program can take based on a certain 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 can be calculated by multiplying the size of each element in the array (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
In the given statement, the array "table" is declared with 2 rows and 3 columns. The initialization values provided are {{0}, {0}}. This means that the first row elements are explicitly initialized to zero, while the second row elements are not explicitly initialized and will therefore have a default value of zero. Hence, only the first row elements are initialized to zero. Additionally, since the second row elements have a default value of zero, all the array elements are effectively initialized to zero.
21.
The statements 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 the statement initializes the variable 'a' with the character 'A' and continues the loop until the value of 'a' is no longer less than or equal to 'Z', which represents 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 storage in memory. For example, an integer requires 4 bytes of storage, while a character requires only 1 byte. Additionally, the size of the array also affects the amount of storage needed. If the array has a larger size, more memory will be required to store all of its elements. Therefore, both the data type and size of the array are factors that determine the amount of storage needed.
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. When an array is declared as static, it is stored in the data segment of memory and all its elements are automatically initialized to 0 by default. Therefore, if we do not explicitly assign any values to the elements of the array, they will all 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
The program is attempting to assign the value of m1 to m2, but arrays cannot be directly assigned to each other in C. Arrays are not considered left values, meaning they cannot be assigned a new value. This results 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 of an array is accessed using the index 0, the second element with index 1, and so on. This convention is followed in C and many other programming languages, making it a common practice for developers. It is important to keep in mind this zero-based indexing when working with arrays in C 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
The maximum number of dimensions an array can have in the C language is not specified by the language itself. It is dependent on the compiler being used. Different compilers may have different limits on the number of dimensions an array can have. Therefore, the maximum number of dimensions allowed for an array in C is compiler dependent.
27.
What is the result of the expression ( 10/3 )*3+5%3 ?
Correct Answer
B. 11
Explanation
The expression is evaluated according to the order of operations. First, the division operation (10/3) is performed, resulting in 3.3333. Then, the multiplication operation (3 * 3) is performed, resulting in 9. Next, the modulus operation (5 % 3) is performed, resulting in 2. Finally, the addition operation (9 + 2) is performed, resulting in 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 program initializes an integer variable 'b' to 0 and an integer array 'c' with values 1 to 9 and 0. It then uses a for loop to iterate through the elements of the array and adds each element to 'b'. Finally, it prints the value of 'b', which is the sum of all the elements in the array. 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 elements. However, only the first three elements are given explicit values of 3. The remaining elements will be automatically initialized to 0. Therefore, the value of num[2] is indeed 3.
30.
Which of the follwing is a string
Correct Answer
B. “abcd”
Explanation
The correct answer is "abcd" because it is enclosed in double quotation marks, which is the standard way to represent a string in most 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 given program will result in an infinite loop. The variable I is initialized to 1 and the while loop condition is I < 5. However, there is no statement inside the loop that increments the value of I. Therefore, the value of I will always remain 1, causing the loop condition to always be true. As a result, the program will continuously print the value of 1 without ever terminating.
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 is because the strcpy function is used to copy a string from one location to another. In this case, it is copying the string "Hello" to the character array str. The other options are incorrect. strcat is used to concatenate strings, not copy them. printf is used to print a formatted string, not copy a string. And assigning a string directly to a character array using the assignment operator (=) is not valid syntax.
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 and then enters a loop where it checks if the value of "I" is divisible by 2 (even number) using the condition "I%2==0". If it is divisible, it increments the count by 1. The loop runs from 0 to 10 (inclusive). Since there are 6 even numbers between 0 and 10 (0, 2, 4, 6, 8, 10), the final value of "count" will be 6.
34.
What will happen if you try to put so many values into an array during the initalization such that its size is exceeded
Correct Answer
B. Possible system malfunction
Explanation
If you try to put too many values into an array during initialization such that its size is exceeded, it can lead to a possible system malfunction. This is because the array may try to access memory locations that are not allocated for it, causing unexpected behavior and potentially crashing 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 mathematics. First, the multiplication of 3 and 4 is performed, resulting in 12. Then, the division of 12 by 5 is done, resulting in 2.4. Next, the division of 10 by 5 is performed, resulting in 2. Then, the addition of 2.4, 2, 8, 1, and the division of 7 by 8 is done, resulting in 11. 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( );". This statement uses the getch() function to read a single character from the keyboard and assigns the result to the character 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 variable sum to 0 and I to 0. It then enters a do-while loop where it adds the value of I to sum and increments I by 1 in each iteration. This continues until I becomes greater than 5. The final value of sum is then printed using the printf statement. Since the loop iterates 5 times and adds the values 1, 2, 3, 4, and 5 to sum, the output will be the sum of these numbers which is 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 determines the number of elements that the array can hold.
39.
Dynamic memory allocation in array results in
Correct Answer
D. Allocation of memory at runtime
Explanation
Dynamic memory allocation refers to the process of allocating memory during the execution of a program, rather than at compile time. This allows the program to request and use memory as needed, which is particularly useful when the size of the array is not known beforehand or may change during runtime. The memory is allocated at runtime, allowing for flexibility and efficient memory usage.
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 called "name" with a size of 5. It then scans for input using the "%s" format specifier, which reads a string from the input. Since the input is "Program", which has 7 characters, it will exceed the size of the array and result in a buffer overflow. This can lead to undefined behavior, including a runtime error. Therefore, the correct answer is "Runtime error".