C Language Exam 1

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Sudha_test
S
Sudha_test
Community Contributor
Quizzes Created: 12 | Total Attempts: 35,612
Questions: 40 | Attempts: 3,881

SettingsSettingsSettings
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 to get in your papers come exam time. Give it a try and all the best as you continue on the programing journey.


Questions and Answers
  • 1. 

    Identify the loop construct:

    • A.

      If-else

    • B.

      Goto

    • C.

      While

    • D.

      Switch-case

    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.

    Rate this question:

  • 2. 

    Which of the following is not a storage class

    • A.

      External

    • B.

      Automatic

    • C.

      Register

    • D.

      Define

    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.

    Rate this question:

  • 3. 

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

    • A.

      # define pie = 22/7

    • B.

      #define pie 22/7

    • C.

      #define pie= 3.142

    • D.

      # Define pie 22/7

    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.

    Rate this question:

  • 4. 

    The minimum number of times the for loop is executed is

    • A.

      0

    • B.

      Cannot be predicted

    • C.

      1

    • D.

      2

    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.

    Rate this question:

  • 5. 

    In switch statement

    • A.

      More than one default allowesd

    • B.

      Default case, if used, should be the last case

    • C.

      Default case, if used, can be placed anywhere

    • D.

      Default case must be present

    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.

    Rate this question:

  • 6. 

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

    • A.

      2

    • B.

      3

    • C.

      Any number

    • D.

      1

    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.

    Rate this question:

  • 7. 

    The storage area for register variables

    • A.

      Cache

    • B.

      Memory

    • C.

      Processor registers

    • D.

      Virtual memory

    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.

    Rate this question:

  • 8. 

    Which of the following statements is false

    • A.

      The initialization and increment parts of a for statement can be empty

    • B.

      The body of do-while statement can be empty

    • C.

      The expression in the condition part of a for statement can be empty

    • D.

      The initialization part of a for statement cannot have more than one initialization

    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.

    Rate this question:

  • 9. 

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

    • A.

      No

    • B.

      Unpredictable

    • C.

      Yes

    • D.

      Error

    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.

    Rate this question:

  • 10. 

    The global variable can be declared

    • A.

      After main

    • B.

      After block

    • C.

      Before main

    • D.

      Within block

    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.

    Rate this question:

  • 11. 

    Which of the following is not correct

    • A.

      While loop is executed atleast once

    • B.

      Do . while loop is executed at least once

    • C.

      While loop is executed only if the condition is true

    • D.

      Dowhile loop is ececuted only if the condition is true

    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.

    Rate this question:

  • 12. 

    printf (“\ “ well done\” ”); what will be the output of this statement

    • A.

      \“well done \”

    • B.

      Well done

    • C.

      “ well done”

    • D.

      \ well done \

    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.

    Rate this question:

  • 13. 

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

    • A.

      0

    • B.

      Run-time error

    • C.

      Undefined

    • D.

      Compilation error

    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.

    Rate this question:

  • 14. 

    The number of elements in array declaration

    • A.

      Dynamically identifies based on largest index used in program

    • B.

      Does not require to be specified

    • C.

      Assume default size as ‘0’

    • D.

      Requires to be specified

    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.

    Rate this question:

  • 15. 

    In C every variable has

    • A.

      A type and size

    • B.

      A type, name, value and size

    • C.

      A name and type

    • D.

      A size and value

    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.

    Rate this question:

  • 16. 

    All the elements in the array must be

    • A.

      Defined

    • B.

      Neither initialized nor defined

    • C.

      Initialized and defined

    • D.

      Initialized

    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.

    Rate this question:

  • 17. 

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

    • A.

      6 bytes

    • B.

      24 bytes

    • C.

      12 bytes

    • D.

      48 bytes

    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.

    Rate this question:

  • 18. 

    If statement is a —————statement

    • A.

      Loop construct

    • B.

      Two way decision

    • C.

      Multiway decision

    • D.

      One-way decision

    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.

    Rate this question:

  • 19. 

    The total memory required for an array

    • A.

      Sizeof (datatype) * 2

    • B.

      Size of (datatype) * size of used array elements

    • C.

      Sizeof (datatype) * sizeof array

    • D.

      Size of (array) * datatype

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

    Rate this question:

  • 20. 

    int table [2][3] ={{0}, {0}} in this statement

    • A.

      None of the element are initialized to zero

    • B.

      Only first row elements are initialized to zero

    • C.

      Only last row elements are initialized to zero

    • D.

      All the array elements are initialized to zero

    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.

    Rate this question:

  • 21. 

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

    • A.

      For(a=‘A’; a

    • B.

      For(a=‘A’; a

    • C.

      For(a=‘a’; a

    • D.

      For(a=’A’ a

    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.

    Rate this question:

  • 22. 

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

    • A.

      Data type

    • B.

      Datatype and size

    • C.

      Run-time requirement

    • D.

      Size

    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.

    Rate this question:

  • 23. 

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

    • A.

      Character constant

    • B.

      A floating point number

    • C.

      0

    • D.

      An undetermined value

    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.

    Rate this question:

  • 24. 

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

    • A.

      Char array cannot be printed directly using printf

    • B.

      Array is not a left value and so cannot be assigned to

    • C.

      Program compiles without error, but prints an unpredictable value

    • D.

      Array cannot be initialized as above

    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.

    Rate this question:

  • 25. 

    Array subscripts in ‘C’ always start at

    • A.

      0

    • B.

      Compiler dependent

    • C.

      1

    • D.

      -1

    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.

    Rate this question:

  • 26. 

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

    • A.

      4

    • B.

      5

    • C.

      Compiler dependent

    • D.

      3

    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.

    Rate this question:

  • 27. 

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

    • A.

      10

    • B.

      11

    • C.

      8

    • D.

      1

    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.

    Rate this question:

  • 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); }

    • A.

      1 3 6 10 15 21 28 32 45 45

    • B.

      55

    • C.

      45

    • D.

      0

    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.

    Rate this question:

  • 29. 

    consider the array definition int num [10] = { 3 ,3 ,3 }; pick the correct answers

    • A.

      This is syntactically wrong

    • B.

      The value of num[8] is 3

    • C.

      This is invalid if it comes within a function

    • D.

      The value of num[2] is 3

    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.

    Rate this question:

  • 30. 

    Which of the follwing is a string

    • A.

      ‘abcd’

    • B.

      “abcd”

    • C.

      Abcd

    • D.

      ‘abcd”

    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.

    Rate this question:

  • 31. 

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

    • A.

      Print the value of I as 1

    • B.

      Warning for no return type for main ( )

    • C.

      Infinite loop

    • D.

      Prints the value of I as11111

    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.

    Rate this question:

  • 32. 

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

    • A.

      Strcpy( str, “Hello” );

    • B.

      Strcat(str,“Hello”);

    • C.

      Printf( str, “Hello” );

    • D.

      Str = “Hello”;

    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.

    Rate this question:

  • 33. 

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

    • A.

      6

    • B.

      3

    • C.

      4

    • D.

      5

    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.

    Rate this question:

  • 34. 

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

    • A.

      Error message from the compiler

    • B.

      Possible system malfunction

    • C.

      Last element data may be overwritten

    • D.

      Nothing

    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.

    Rate this question:

  • 35. 

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

    • A.

      11

    • B.

      10

    • C.

      12

    • D.

      9

    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.

    Rate this question:

  • 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;

    • A.

      Ch = getch( );

    • B.

      Printf( “%c”, ch );

    • C.

      While(!kbhit)

    • D.

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

    Rate this question:

  • 37. 

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

    • A.

      28

    • B.

      10

    • C.

      15

    • D.

      21

    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.

    Rate this question:

  • 38. 

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

    • A.

      Value of the array element

    • B.

      Subscript value

    • C.

      Address value

    • D.

      Size of an array

    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.

    Rate this question:

  • 39. 

    Dynamic memory allocation in array results in

    • A.

      Allocation of memory at debugging time

    • B.

      Allocation of memory at file saving time

    • C.

      Allocation of memory at compile time

    • D.

      Allocation of memory at runtime

    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.

    Rate this question:

  • 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;

    • A.

      Progr

    • B.

      Prog

    • C.

      Program

    • D.

      Runtime error

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

    Rate this question:

Quiz Review Timeline +

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
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.