1.
Identify the loop construct:
Correct Answer
C. While
Explanation
The loop construct identified in this question is "while". The "while" loop is used to repeatedly execute a block of code as long as a specified condition is true. It checks the condition before executing the code, and if the condition is true, it continues to execute the code block. Once the condition becomes false, the loop terminates and the program continues with the next line of code after the loop.
2.
Which of the following is not a storage class
Correct Answer
D. Define
Explanation
The storage classes in C programming language define the scope and lifetime of variables. The "define" option mentioned in the question is not a storage class. In C, "define" is used to create a macro or a constant value using the preprocessor directive #define. It does not deal with the scope or lifetime of variables like the storage classes do.
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" preprocessor directive followed by the name of the constant "pie" and its value "22/7". This creates a symbolic constant called "pie" with the value of the mathematical constant pi (approximately 3.142).
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 condition in the for loop is initially false, 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, if a default case is used, it can be placed anywhere within the switch statement. This means that it doesn't necessarily have to be the last case. The default case is executed when none of the other cases match the value being switched on. So, if the default case is placed before other cases, it will be executed if none of those cases match.
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 is executed. This means that the loop will always execute at least once. After each iteration, the condition is checked, and if it is true, the loop will continue. Therefore, there can be any number of while statements in a do...while loop, depending on the condition.
7.
The storage area for register variables
Correct Answer
C. Processor registers
Explanation
Processor registers are small, high-speed storage areas located within the CPU. They are used to store data that is frequently accessed by the processor, such as variables and intermediate results of calculations. Register variables are stored directly in these registers, providing fast access and improving the overall performance of the program. This is why the storage area for register variables is referred to as processor registers.
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 us to initialize multiple variables or perform multiple initialization operations using commas. Therefore, it is possible to have more than one initialization in the initialization part of a for statement.
9.
Consider the segment
If(1) printf(“yes”);
else printf(“no”);
what will be the output
Correct Answer
C. Yes
Explanation
The condition in the if statement is 1, which is considered as true in C programming. Therefore, the code inside the if block will be executed, resulting in the output "yes" being printed.
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 the main function, and can be accessed and used by any function within the program. Declaring a variable before the main function allows it to have a global scope, meaning it can be accessed from anywhere in the program. This is useful when a variable needs to be shared and used by multiple functions.
11.
Which of the following is not correct
Correct Answer
A. While loop is executed atleast once
Explanation
The explanation for the given correct answer is that a while loop is not executed at least once. This is because the while loop checks the condition before executing the code inside the loop. If the condition is initially false, the code inside the loop will not be executed at all.
12.
printf (“\ “ well done\” ”); what will be the output of this statement
Correct Answer
C. “ well done”
Explanation
The given code snippet is using the printf function to print the string "\ " well done\" ". However, the backslash character "\" is an escape character in C programming, so it is used to escape the following character. In this case, the backslash before the double quotes is escaping the double quotes, so the output will be " well done" with a space before the "well done" 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 variable 'y' but does not initialize it. In C, static variables are automatically initialized to 0. Therefore, when the program prints the value of 'y', it will output 0.
14.
The number of elements in array declaration
Correct Answer
D. Requires to be specified
Explanation
In array declaration, the number of elements usually needs to be specified. This is because the compiler needs to allocate memory for the array based on the specified size. If the size is not specified, the compiler will not know how much memory to allocate, leading to potential errors or unexpected behavior. Therefore, it is necessary to specify the number of elements in the array declaration.
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, float, or character. The name is the identifier used to refer to the variable in the program. The value is the actual data stored in the variable. The size represents the amount of memory allocated to store the variable, which depends on its type. Having a type, name, value, and size for each variable is essential for proper memory allocation and data manipulation in the C programming language.
16.
All the elements in the array must be
Correct Answer
A. Defined
Explanation
The correct answer is "defined" because in order to use elements in an array, they must be defined, meaning that they have been declared and given a value. Initialization is not necessary, as the elements can be assigned values later on. However, they must be defined before they can be used in any operations or calculations.
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 this array is an integer, which typically requires 4 bytes of memory. Since there are a total of 4*3=12 elements in the array, the total memory allotted will be 12*4=48 bytes. Therefore, the correct answer is 24 bytes.
18.
If statement is a —————statement
Correct Answer
D. One-way decision
Explanation
A one-way decision statement is a type of programming statement that allows for the execution of a block of code only if a certain condition is true. It does not provide any alternative paths or options for the code execution. In other words, it allows for a single path of execution based on the condition being true or false. This is different from other types of decision statements such as two-way or multiway decision statements, which provide multiple paths or options for code execution based on different conditions.
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 size of the array is determined by multiplying the size of each element (datatype) by the total number of elements in the array (sizeof array). This calculation gives the total memory required for the array.
20.
Int table [2][3] ={{0}, {0}} in this statement
Correct Answer
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 provided within double curly brackets. In this case, the elements are initialized to zero. Since no specific values are assigned to any element, all the elements in the array are 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
This statement `for(a=’A’ a` is the correct answer because it initializes the variable `a` with the character 'A' and loops through the character set from A to Z. The loop will continue as long as `a` is less than or equal to '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 have different sizes in memory, and the size of the array also affects the total storage required. For example, an array of integers will require more storage than an array of characters because integers typically have a larger size in memory. Similarly, a larger array will require more storage than a smaller array, regardless of the data type. Therefore, both the data type and size of the array are important factors in determining the amount of storage required.
23.
If we don’t initialize a static array, what will be the elements set to:
Correct Answer
D. An undetermined value
Explanation
If we don't initialize a static array, the elements will be set to an undetermined value. This means that the values of the elements in the array will be unpredictable and could be any random value that happens to be stored in memory at that time. Therefore, it is important to always initialize static arrays to avoid accessing and using undefined values.
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
D. Array cannot be initialized as above
Explanation
The given program is trying to assign the value of one character array (m1) to another character array (m2) using the assignment operator (=). However, in C, arrays cannot be assigned directly. Instead, each element of the array needs to be copied individually. Therefore, the program is incorrect because it is trying to assign the entire array m1 to m2, which is not allowed.
25.
Array subscripts in ‘C’ always start at
Correct Answer
A. 0
Explanation
In 'C', 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 the subscript 1, and so on. This convention is followed in 'C' programming language and is important to keep in mind while working with arrays to avoid any indexing 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 dependent on the compiler being used. Different compilers may have different limitations on the number of dimensions allowed for an array. Therefore, the maximum number of dimensions is not fixed and can vary based on the 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.33. The expression 3+5%3 evaluates to 4 because the remainder of 5 divided by 3 is 2, and then 3 is added to 2. Therefore, the result of the entire expression is 3 + 4 which equals 7.
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 'a' and sets it to 0. It also initializes an integer variable 'b' and sets it to 0. It then creates an integer array 'c' with 10 elements and assigns the values 1, 2, 3, 4, 5, 6, 7, 8, 9, and 0 to the elements respectively.
Next, a for loop is used to iterate through the array 'c' and add each element to 'b'. After the loop, the value of 'b' is printed.
Since 'b' is initialized to 0 and each element of 'c' is added to it in the loop, the final value of 'b' is the sum of all the elements in 'c', which 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 size 10, but only provides 3 values. In this case, the remaining elements of the array will be automatically initialized to 0. Therefore, the value of num[2] will be 3, as it is the third element of the array.
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 correct syntax for representing a string in most programming languages. The other options are either not enclosed in 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 because the condition in the while loop (I < 5) is always true and there is no statement inside the loop to change the value of I. Therefore, the program will keep printing the value of I (which is 1) indefinitely.
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 strcpy() function is used to copy the string "Hello" into the character array str. It takes two arguments - the destination array (str) and the source string ("Hello"). It copies the source string into the destination array, overwriting any previous content in the 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 is a loop that 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, the count variable is incremented by 1. Since there are 6 even numbers between 0 and 10 (0, 2, 4, 6, 8, 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 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 and exceed its size, it can lead to a possible system malfunction. This is because exceeding the array's size can cause memory corruption, leading to unpredictable behavior in the system. It can result in memory leaks, crashes, or other system errors, making the system malfunction.
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 expression given can be evaluated using the order of operations in mathematics. First, we perform the multiplication and division from left to right. 3 multiplied by 4 is 12, and when divided by 5, the result is 2.4. Similarly, 10 divided by 5 is 2.0. Then, we perform the addition and subtraction from left to right. Adding 2.4, 2.0, 8, -1, and 0.875 (7 divided by 8) gives us a final result of 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 module calculates the sum of numbers from 1 to 5 using a do-while loop. The variable "sum" is initialized to 0 and the variable "I" is initialized to 0. Inside the do-while loop, the value of "I" is added to "sum" and then "I" is incremented by 1. This process continues until "I" becomes greater than 5. Therefore, the final value of "sum" is 15, which is the correct answer.
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 in array allows for the allocation of memory at runtime. This means that the memory is allocated during the execution of the program, allowing for flexibility in the amount of memory needed. Unlike static memory allocation, which occurs at compile time, dynamic memory allocation allows for the allocation and deallocation of memory as needed during program execution. This is particularly useful when the size of the array is not known beforehand or may change during runtime.
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 a string input and store it in the "name" array. Since the array can only hold 5 characters, any input longer than that will result in a buffer overflow. In this case, the input "Program" has 7 characters, so only the first 4 characters "Prog" will be stored in the array. Finally, the program uses the printf function to print the contents of the "name" array, which will output "Prog".
41.
What will be the output of the following program?
#include<stdio.h>
int main()
{
char numbers[5][6] = {"Zero","One","Two","Three","Four"};
printf("%s is %c",&numbers[4][0],numbers[0][0]);
return 0;
}
Correct Answer
A. Four is Z
Explanation
The program declares a 2D array of characters called "numbers" with 5 rows and 6 columns. It initializes the array with the strings "Zero", "One", "Two", "Three", and "Four".
In the printf statement, it prints the first character of the string at index 4 of the second dimension of the "numbers" array (which is the string "Four"), followed by the first character of the string at index 0 of the first dimension of the "numbers" array (which is the string "Zero").
Therefore, the output of the program will be "Four is Z".
42.
Which one of the following is an example of storage class in C?
Correct Answer
B. Extern
Explanation
The correct answer is "extern". In C programming, "extern" is a storage class that is used to declare a variable or function that is defined in another source file. It is used to provide a reference to a global variable or function that is defined in a different file. The "int" and "float" are data types in C, not storage classes. Therefore, option 2, "extern", is the correct example of a storage class in C.
43.
What will be the output of the following program?
#include<stdio.h>
int main()
{
int a = 1, b = 2, c = 3;
printf("The value of a is %d", ++a);
func();
printf(" The value of a is %d", ++a);
return 0;
}
void func()
{
int a = 10;
return 0;
}
Correct Answer
B. The value of a is 2 The value of a is 3
Explanation
The output of the program will be "The value of a is 2 The value of a is 3". This is because the variable "a" is incremented twice using the pre-increment operator (++a) before the first printf statement and before the second printf statement. The function func() does not affect the value of "a" as it has its own local variable with the same name.
44.
What is the output of the below program?
#include<stdio.h>
int main()
{
printf("%c", "abcdefgh"[6]);
return 0;
}
Correct Answer
A. G
Explanation
The program is using array indexing to access the 6th element of the string "abcdefgh", which is 'g'. The printf function then prints this character. Therefore, the output of the program is 'g'.
45.
What will be the output of the following program?
#include<stdio.h>
#define putchar(c) printf("%c",c)
int main()
{
char s='c';
putchar (s);
return 0;
}
Correct Answer
D. C
Explanation
The program defines a macro called putchar that takes a character as an argument and prints it using the printf function. In the main function, a character variable s is assigned the value 'c'. Then, the putchar macro is called with s as the argument, which will print the character 'c'. Therefore, the output of the program will be 'c'.
46.
What will be the output of the following program?
#include<stdio.h>
enum {TRUE, FALSE};
int main()
{
int i=1;
do{
printf("%d\t",i);
i++;
if(i > 5)
break;
}
while(TRUE);
return 0;
}
Correct Answer
D. 1
Explanation
The program uses a do-while loop to print the value of the variable i. It starts with i=1 and increments it by 1 in each iteration. The condition for the loop to continue is TRUE, which is equivalent to the value 1. However, there is a break statement inside the loop that will be executed when i becomes greater than 5. Therefore, the loop will only iterate 5 times, printing the values 1, 2, 3, 4, and 5.
47.
What will be the output of the following program ?
#include<stdio.h>
int main(){
typedef struct{char ch;}st;
st s1 = {'c'}; st s2 = s1;
if(s1 == s2)
printf("Successful");
return 0;
}
Correct Answer
B. Compiler error
Explanation
The program will result in a compiler error. This is because the comparison operator (==) cannot be used to compare two struct variables. Struct variables cannot be directly compared using the equality operator.
48.
What is the keyword used to turn off the compiler optimization of a variable?
Correct Answer
B. Volatile
Explanation
The keyword "volatile" is used to turn off the compiler optimization of a variable. When a variable is declared as volatile, it tells the compiler that the value of the variable can be changed unexpectedly by external factors, such as another thread or hardware. This prevents the compiler from optimizing the variable by caching its value, ensuring that the variable is always read from memory and not from a cached value. This is useful in scenarios where the variable's value can be modified outside of the program's control.
49.
What will be the output of the following program?
#include<stdio.h>
int main()
{
fun();
}
fun()
{
printf("you are in fun");
main();
return 0;
}
Correct Answer
D. Stack overflow
Explanation
The program will go into an infinite loop and print "you are in fun" endlessly. This is because the function fun() is calling the main() function recursively, creating an infinite loop. Eventually, the recursive calls will cause a stack overflow error, leading to the program crashing.
50.
Which one of the following is the correct way of declaring main() function when it receives command line arguments?
Correct Answer
D. Main(int argc,char* argv[ ])
Explanation
The correct way of declaring the main() function when it receives command line arguments is "main(int argc,char* argv[ ])". In this declaration, "argc" represents the number of command line arguments passed to the program, and "argv" is an array of strings containing the actual arguments.