C Language Exam 1

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Sudha_test
S
Sudha_test
Community Contributor
Quizzes Created: 12 | Total Attempts: 38,126
| Attempts: 3,965 | Questions: 40
Please wait...
Question 1 / 40
0 %
0/100
Score 0/100
1. Array subscripts in ‘C’ always start at

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.

Submit
Please wait...
About This Quiz
C Language Exam 1 - Quiz

C language is the first language that most programmers get introduced to programming. The quiz below is a sample test to show you the questions you would expect... see moreto get in your papers come exam time. Give it a try and all the best as you continue on the programing journey.
see less

2. Identify the loop construct:

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.

Submit
3. Which of the follwing is a string

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.

Submit
4. The global variable can be declared

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.

Submit
5. The amount of storage required for holding elements of the array depends on

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.

Submit
6. How would you copy the name “Hello” to a character array (i.e. string) declared as char str[10];

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.

Submit
7. What is the result of the expression ( 10/3 )*3+5%3 ?

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.

Submit
8. The maximum number of dimension an array can have in C language is

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.

Submit
9. 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;

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'.

Submit
10. Which of the following is not a storage class

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.

Submit
11. The value within the [] brackets in an array declaration specifies

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.

Submit
12. The statements that prints out the character set from A-Z is, where a is an integer variable

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.

Submit
13. What is the output of the following module sum=0; I=0; do{ sum+=I; I++; }while(I<=5); printf(“%d”, sum);

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.

Submit
14. Consider the segment If(1) printf(“yes”); else printf(“no”); what will be the output

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.

Submit
15. Consider the array definition int num [10] = { 3 ,3 ,3 }; pick the correct answers

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.

Submit
16. If we don’t initialize a static array, what will be the elements set to:

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.

Submit
17. Dynamic memory allocation in array results in

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.

Submit
18. In C every variable has

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.

Submit
19. How many while statements are possible in do.... While loop?

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.

Submit
20. The storage area for register variables

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.

Submit
21. Give the output of the following program: #include < stdio.h > main() {int I=1; while (I < 5) {printf(“%d”, I); }} /* End of Main */

Explanation

The given program will result in an infinite loop. The variable I is initialized to 1 and the while loop condition is I

Submit
22. What is the output of the following program main() {static int y; printf (“%d\n”, y); }

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.

Submit
23. Which of the following is a correct way of defining a symbolic constant pie in C

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.

Submit
24. The minimum number of times the for loop is executed is

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.

Submit
25. The total memory required for an 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).

Submit
26. Count=0; for ( I=0;I<=10; I++) {if(I%2==0) count++; }printf(“%d”, count); Pick out the correct value for count

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.

Submit
27. Printf (“\ “ well done\” ”); what will be the output of this statement

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.

Submit
28. How many bytes will be allotted for the declaration int num[4] [3]

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.

Submit
29. 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); }

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.

Submit
30. Compute the result of the following expression in ‘C’. A=3*4/5+10/5+8-1+7/8

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.

Submit
31. Which of the following is not correct

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.

Submit
32. Which of the following statements is false

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.

Submit
33. The number of elements in array declaration

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.

Submit
34. What is wrong with the following program main() { char m1[9]= “message1”; char m2[9]=“message2”; m2=m1; printf(“msg is %s”,m2); }

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.

Submit
35. If statement is a —————statement

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.

Submit
36. In switch statement

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.

Submit
37. All the elements in the array must be

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.

Submit
38. What will happen if you try to put so many values into an array during the initalization such that its size is  exceeded

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.

Submit
39. 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;

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".

Submit
40. Int table [2][3] ={{0}, {0}} in this statement

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.

Submit
View My Results

Quiz Review Timeline (Updated): Mar 22, 2023 +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 22, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Jan 11, 2010
    Quiz Created by
    Sudha_test
Cancel
  • All
    All (40)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
Array subscripts in ‘C’ always start at
Identify the loop construct:
Which of the follwing is a string
The global variable can be declared
The amount of storage required for holding elements of the array...
How would you copy the name “Hello” to a character array (i.e....
What is the result of the expression ( 10/3 )*3+5%3 ?
The maximum number of dimension an array can have in C language is
Which of the following statements would read a single character from...
Which of the following is not a storage class
The value within the [] brackets in an array declaration specifies
The statements that prints out the character set from A-Z is, where a...
What is the output of the following module ...
Consider the segment ...
Consider the array definition ...
If we don’t initialize a static array, what will be the elements set...
Dynamic memory allocation in array results in
In C every variable has
How many while statements are possible in do.... While loop?
The storage area for register variables
Give the output of the following program: ...
What is the output of the following program ...
Which of the following is a correct way of defining a symbolic...
The minimum number of times the for loop is executed is
The total memory required for an array
Count=0; ...
Printf (“\ “ well done\” ”); what will be the output of this...
How many bytes will be allotted for the declaration int num[4] [3]
Output of the below program ...
Compute the result of the following expression in ‘C’....
Which of the following is not correct
Which of the following statements is false
The number of elements in array declaration
What is wrong with the following program ...
If statement is a —————statement
In switch statement
All the elements in the array must be
What will happen if you try to put so many values into an array during...
Main() ...
Int table [2][3] ={{0}, {0}} in this statement
Alert!

Advertisement