1.
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 copies the string "Hello" to the character array str. The other options are incorrect. strcat(str, "Hello") would concatenate the string "Hello" to the existing string in str. printf( str, "Hello" ) is not a valid function call as printf is used for printing formatted output. str = "Hello" is also incorrect as you cannot assign a string directly to a character array.
2.
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 code initializes a variable "count" to 0. It then runs a loop from 0 to 10 (inclusive) and checks if each value of "I" is divisible by 2 (i.e., even). If "I" is even, 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) in the range, the correct value for "count" is 6.
3.
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. It determines the number of elements that can be stored in the array.
4.
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 A=3*4/5+10/5+8-1+7/8 can be simplified as follows:
- First, we perform the multiplication and division operations from left to right: 3*4/5 = 12/5
- Next, we perform the addition and subtraction operations from left to right: 12/5 + 10/5 + 8 - 1 + 7/8 = 2.4 + 2 + 8 - 1 + 0.875
- Finally, we add up all the values: 2.4 + 2 + 8 - 1 + 0.875 = 11.275
Since the result is a decimal number, we round it down to the nearest whole number, which is 11.
Therefore, the correct answer is 11.
5.
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 the runtime of a program. This means that the memory for the array is allocated dynamically, based on the program's needs, rather than at compile time or any other specific time. The advantage of dynamic memory allocation is that it allows for flexibility in memory usage, as the size of the array can be determined and adjusted during runtime.
6.
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 'I' is initialized to 0. Inside the loop, 'sum' is incremented by the value of 'I' and 'I' is incremented by 1. This process continues until 'I' becomes greater than 5. Finally, the value of 'sum' is printed using the printf statement. In this case, the final value of 'sum' would be 15, which is the correct answer.
7.
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 correct syntax for representing a string in many programming languages. The other options either lack the quotation marks or have mismatched quotation marks, making them invalid representations of a string.
8.
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 contains a while loop that will continue executing as long as the condition "I < 5" is true. However, there is no statement inside the loop that modifies the value of I, so it will always remain 1. Therefore, the condition will always be true and the loop will run indefinitely, resulting in an infinite loop.
9.
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 the array is allocated a fixed amount of memory based on its size during initialization. When you try to store more values than the allocated memory can hold, it can cause memory corruption and potentially crash the system or cause unexpected behavior.
10.
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'.
11.
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 called "num" with a size of 10 and assigns the first three elements with the value 3. Since array indices start from 0, the value of num[2] refers to the third element in the array, which is indeed 3. Therefore, the statement "the value of num[2] is 3" is correct.
12.
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 first initializes variables a and b, and an array c with 10 elements. It then enters a for loop that iterates from 0 to 9. Inside the loop, it adds the value of each element in array c to the variable b. After the loop, it prints the value of b, which is the sum of all elements in array c. Therefore, the output of the program will be 45.
13.
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 C language is not fixed and depends on the compiler being used. Different compilers may have different limits on the number of dimensions allowed for an array. Therefore, the correct answer is "compiler dependent".
14.
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. Multiplying this by 3 gives us 9.9999. The modulus operator (%) calculates the remainder of dividing 5 by 3, which is 2. Adding 9.9999 and 2 gives us 11. Therefore, the result of the expression is 11.
15.
Array subscripts in ‘C’ always start at
Correct Answer
A. 0
Explanation
In the programming language 'C', array subscripts always start at 0. This means that the first element of an array is accessed using the subscript 0, the second element with the subscript 1, and so on. This is a fundamental concept in 'C' and many other programming languages, where arrays are typically implemented as contiguous blocks of memory. Starting the subscripts at 0 allows for efficient memory access and indexing calculations.
16.
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 statement initializes the variable "a" with the character 'A' and then loops while "a" is less than or equal to the character set's last character, which is 'Z'. Therefore, it will print out the character set from A to Z. The other statements either have syntax errors or do not cover the entire character set.
17.
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 both the data type and the size. Different data types have different sizes in memory, so the storage needed will vary based on the data type used. Additionally, the size of the array, which determines the number of elements it can hold, also affects the amount of storage required. Therefore, both the data type and the size of the array are factors that determine the amount of storage needed.
18.
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. This means that each element in the array will have a value of 0 by default.
19.
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 assigned to in this way. Arrays are not considered left values, meaning they cannot be assigned to like variables. This causes a compilation error in the program.
20.
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 sizeof operator returns the size in bytes of the datatype, and multiplying it by the sizeof array gives the total memory required for the array.
21.
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]" indicates a two-dimensional array with 4 rows and 3 columns. Since each element in the array is of type "int", which typically takes up 4 bytes of memory, the total memory allocated can be calculated by multiplying the number of rows by the number of columns by the size of each element. In this case, 4 rows multiplied by 3 columns multiplied by 4 bytes gives us a total of 24 bytes.
22.
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 decision between two possible outcomes. It typically uses a conditional expression to evaluate a condition and then executes different blocks of code based on whether the condition is true or false. This type of statement is commonly used in programming to implement if-else constructs, where one block of code is executed if the condition is true and another block is executed if the condition is false.
23.
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 assign any value to it. In C, static variables are automatically initialized to zero. Therefore, when the program prints the value of "y", it will output 0.
24.
printf (“\ “ well done\” ”); what will be the output of this statement
Correct Answer
C. “ well done”
Explanation
The correct answer is " well done". This is because the backslashes (\) before and after the quotation marks (\") are escape characters, which indicate that the quotation marks should be treated as part of the string and not as string delimiters. Therefore, the output will include the quotation marks and the space before and after the words "well done".
25.
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 incorrect. A while loop is only executed if the condition is true. If the condition is initially false, the loop will not be executed at all.
26.
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 declared outside of any function, including the main function, and can be accessed by any function within the program. This allows the variable to have a global scope and be accessible throughout the entire program. By declaring the variable before the main function, it ensures that the variable is available for use by any function that may need it.
27.
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 at the end of each iteration. This means that the loop will continue executing as long as the condition is true. Since the condition can be any boolean expression, there is no limit to the number of while statements that can be used in a do...while loop. Therefore, the correct answer is "any number".
28.
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 CPU that are used to store data that needs to be accessed quickly. Register variables are variables that are stored in these processor registers rather than in main memory. Storing variables in processor registers can result in faster access times compared to storing them in cache or main memory. Therefore, the correct answer is processor registers.
29.
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. This is done by separating the initializations with commas. Therefore, the statement "The initialization part of a for statement cannot have more than one initialization" is false.
30.
Consider the segment
If(1) printf(“yes”);
else printf(“no”);
what will be the output
Correct Answer
C. Yes
Explanation
The output will be "yes" because the condition in the if statement (1) is true. Therefore, the code inside the if block will be executed, which is to print "yes" using the printf function.
31.
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, the default case does not require a specific position and can be placed anywhere within the switch statement. This allows for flexibility in the code structure and logic, as the default case can be positioned based on the specific requirements of the program.
32.
The minimum number of times the for loop is executed is
Correct Answer
A. 0
Explanation
The for loop is a control structure that executes a block of code repeatedly until a certain condition is met. In this case, the minimum number of times the for loop is executed is 0. This means that the loop will not execute at all if the condition is not met initially. Therefore, the correct answer is 0.
33.
Identify the loop construct:
Correct Answer
C. While
Explanation
The correct answer is "while". The while loop construct is used to repeatedly execute a block of code as long as a certain condition is true. It first checks the condition and if it is true, the code inside the loop is executed. Once the code is executed, the condition is checked again and if it is still true, the code is executed again. This process continues until the condition becomes false.
34.
Which of the following is not a storage class
Correct Answer
D. Define
Explanation
The storage class "define" does not exist in the C programming language. The other three options, external, automatic, and register, are all valid storage classes in C. The "define" option is most likely included in the question to confuse the reader, as it is a common keyword used in preprocessor directives, but it is not a storage class.
35.
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 constant name (pie) and its value (22/7). This creates a macro that replaces every occurrence of "pie" in the code with the value 22/7.
36.
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 scans for input and stores it in the "name" array. Since the input is "Program", which is 7 characters long, it will only store the first 4 characters ("Prog") in the "name" array. Finally, it prints the contents of the "name" array, which is "Prog". Therefore, the output of the program will be "Prog".
37.
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 creates a 2-dimensional character array called "numbers" with 5 rows and 6 columns. Each row represents a word. In the printf statement, it prints the character at the first index of the 5th row of the "numbers" array, which is 'F', and the character at the first index of the 1st row of the "numbers" array, which is 'Z'. Therefore, the output will be "Four is Z".
38.
Which one of the following is an example of storage class in C?
Correct Answer
B. Extern
Explanation
The correct answer is "extern" because it is a storage class in the C programming language. The "extern" keyword is used to declare a variable that is defined in another file, allowing the variable to be accessed by multiple files in a program. This storage class is commonly used when creating global variables that need to be shared across multiple source files.
39.
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 value of a is incremented by 1 using the pre-increment operator (++a) before the first printf statement. Then the function func() is called, but it does not affect the value of a. Finally, after the function call, the value of a is again incremented by 1 before the second printf statement.
40.
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 character at index 6 of the string "abcdefgh". Since array indexing starts at 0, the character at index 6 is 'g'. Therefore, the output of the program will be 'g'.
41.
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 which 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 the argument s, which is 'c'. As a result, the character 'c' is printed. Therefore, the output of the program will be c.
42.
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 and increments it by 1 each time. It also includes a condition that if i becomes greater than 5, the loop will break. Since the condition of the loop is set to TRUE, the loop will continue indefinitely until it is manually broken. In this case, the loop will print the numbers 1, 2, 3, 4, and 5 before breaking out of the loop. Therefore, the output of the program will be "1 2 3 4 5".
43.
C language has been developed by?
Correct Answer
B. Dennis Ritchie
Explanation
Dennis Ritchie is the correct answer because he is one of the main developers of the C programming language. Along with Ken Thompson, Ritchie created C at Bell Labs in the early 1970s. C became widely used and influential in the field of computer programming, serving as the foundation for many other programming languages. Ritchie's contributions to the development of C and his work on Unix have had a lasting impact on the field of computer science.
44.
C can be used on?
Correct Answer
D. All of the above
Explanation
The correct answer is "All of the above" because C is a programming language that can be used on multiple operating systems, including MS-DOS, Linux, and Windows. It is a versatile language that is not limited to a specific platform, allowing developers to write code that can run on different operating systems without major modifications.
45.
C programs are converted into the machine language with the help of?
Correct Answer
B. Compiler
Explanation
C programs are converted into machine language with the help of a compiler. A compiler is a software tool that translates the entire C program into machine code that can be directly executed by the computer's processor. It analyzes the source code, checks for errors, and generates the corresponding machine code instructions. This process is known as compilation and is essential for the execution of C programs on a computer.
46.
The real constant in C can be expressed in which of the following forms?
Correct Answer
D. Both Fractional and Exponetial
Explanation
The real constant in C can be expressed in both fractional and exponential forms. This means that a real constant in C can be represented as a fraction or in scientific notation with an exponent. For example, a real constant can be written as 0.5 or as 5e-1. Both forms are valid ways to express a real constant in C.
47.
A character variable can at a time score?
Correct Answer
A. 1 character
Explanation
A character variable can at a time store only one character. This is because a character variable is designed to hold a single character value. It cannot store multiple characters or a string of characters. Therefore, the correct answer is 1 character.
48.
The maximum value that an integer constant can have is?
Correct Answer
B. 32767
Explanation
The maximum value that an integer constant can have is 32767. This is because in most programming languages, integers are typically represented using a fixed number of bits, such as 16 bits. With 16 bits, the maximum value that can be represented is 2^(16-1) - 1, which equals 32767.
49.
A-C variable cannot start with?
Correct Answer
D. Both (2) and (3)
Explanation
The correct answer is both (2) and (3). This means that a variable in programming cannot start with a number or a special symbol other than an underscore. Variables must start with an alphabet character. This is because programming languages have specific rules for naming variables, and starting with a number or a special symbol can cause syntax errors or confusion in the code.
50.
Linux was developed mainly using C language.
Correct Answer
A. True
Explanation
Linux was developed mainly using the C language because C is a high-level programming language that allows for efficient and low-level programming. It provides direct access to memory and hardware, making it suitable for developing an operating system like Linux. Additionally, C is portable and can be easily adapted to different hardware architectures, which is crucial for an operating system that needs to run on various devices. Therefore, it is true that Linux was primarily developed using the C language.