C Programming Exam Quiz!

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 Gaurabhkumar750
G
Gaurabhkumar750
Community Contributor
Quizzes Created: 1 | Total Attempts: 742
Questions: 40 | Attempts: 742

SettingsSettingsSettings
C Programming Exam Quiz! - Quiz


Do you understand C Programming? It is often a wellspring of confusion for those who are not as advanced with computers. The focus here is identifying a loop construct, storage class, what is in a switch statement, and when the global variable can be declared. You must know a fair amount of mathematics to understand C Programming. If you are a computer major, you will not be disappointed with this awesome quiz.


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" because it is a loop construct that allows a block of code to be repeatedly executed as long as a specified condition is true. The "while" loop first checks the condition, and if it is true, the code inside the loop is executed. This process continues until the condition becomes false, at which point the loop is exited.

    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 programming languages. The options "external," "automatic," and "register" are all valid storage classes that define how variables are stored and accessed in memory. However, "define" is not a recognized storage class and does not have any specific meaning in this context.

    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
    This is the correct way of defining a symbolic constant pie in C because it uses the correct syntax for the #define directive, which is followed by the name of the constant (pie in this case) and its corresponding value (22/7). The value is not assigned using the = symbol, but rather by leaving a space between the constant name and its value.

    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's condition is not initially satisfied, the loop will not execute 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
    In a switch statement, the default case is optional and can be placed anywhere within the switch block. It does not have to be the last case. The default case is executed when none of the other cases match the value being evaluated. It provides a fallback option for handling unexpected or unhandled values. However, it is good practice to place the default case at the end of the switch block to make the code more readable and to follow common conventions.

    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
    A do...while loop is a type of loop where the code block is executed at least once, and then the condition is checked. If the condition is true, the code block is executed again. This loop will continue until the condition becomes false. Therefore, any number of while statements are possible in a do...while loop, as long as the condition is true.

    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
    Processor registers are a small set of high-speed memory locations within the processor itself. They are used to store data that is frequently accessed by the processor, such as variables and intermediate results during calculations. Register variables are variables that are stored in processor registers instead of main memory. Storing variables in registers can improve performance because accessing data from registers is much faster than accessing data from memory. Therefore, processor registers are the most suitable storage area for register variables.

    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 multiple variables to be initialized and can include multiple expressions separated by commas. Therefore, the statement "The initialization part of a for statement cannot have more than one initialization" is false.

    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 given segment is an if-else statement. If the condition (1) is true, then the code inside the if block will execute, which is to print "yes". Since the condition is 1, which is considered true in C programming, the output will be "yes".

    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 are variables that can be accessed and used throughout the entire program. They are typically declared before the main function because they need to be accessible to all other functions and blocks within the program. Declaring the global variable before main ensures that it is available and can be used by any function or block within the program.

    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 body is executed. If the condition is false initially, the loop body will not be executed at all. Therefore, it is possible for a while loop to not 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 given statement will output " well done" (with a space before and after). This is because the printf function is used to print the string " well done" (including the space characters) to the console. The backslashes before and after the double quotes are escape characters, which are used to include special characters within the string. In this case, the backslashes are used to include the double quotes within the 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" inside the main function. Since static variables are initialized to zero by default, the value of "y" is 0. The program then prints the value of "y" using the printf function. Therefore, the output of the program is 0.

    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
    The correct answer is "requires to be specified". In array declaration, the number of elements needs to be specified so that the compiler can allocate the appropriate amount of memory for the array. If the number of elements is not specified, the compiler will not know how much memory to allocate, resulting in a compilation error.

    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, name, value, and size. The type determines the kind of data that the variable can hold, such as integer, character, or floating-point. The name is used to identify the variable and access its value. The value is the actual data stored in the variable. The size represents the amount of memory allocated for the variable, which depends on its type.

    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 in order for an element to be used in an array, it must be defined, meaning that it has been declared and given a specific type. Initialization is not necessary for an element to be considered defined in an array.

    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. Since an int data type typically requires 4 bytes of memory, each element in the array will take up 4 bytes. Therefore, the total memory allotted for the array will be 4 bytes * 4 rows * 3 columns, which equals 24 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 the program to make a choice between two possible paths based on a condition. It typically uses the keywords "if" and "else" to specify the conditions and the corresponding actions to be taken. This type of statement is commonly used when there are two alternative courses of action depending on the evaluation of a 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 is calculated by multiplying the size of each element (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
    The given statement initializes a 2-dimensional array called "table" with 2 rows and 3 columns. The initialization values are given as {{0}, {0}}, which means that the first row elements are explicitly initialized to zero. However, since the second row is not specified, it is assumed to be initialized to zero as well. Therefore, all the array elements are initialized to zero.

    Rate this question:

  • 21. 

    The statement 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 'A' is the ASCII value of the character 'A', and by incrementing the variable 'a' in each iteration of the loop, it will print out 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 memory to store their values, and the size of the array determines how many elements can be stored. Therefore, both the data type and size of the array are factors that determine the amount of storage required.

    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.

    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
    In the given program, the variable "m2" is declared as an array of characters. However, arrays are not assignable in C, meaning that we cannot directly assign one array to another. This is because arrays decay into pointers, and pointers cannot be assigned to. Therefore, the line "m2=m1;" is incorrect and will result 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 in an array is accessed using the subscript 0, the second element with subscript 1, and so on. This convention is followed in C and many other programming languages, and it is important to keep in mind when working with arrays 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
    In C language, the maximum number of dimensions an array can have is compiler dependent. This means that the maximum number of dimensions allowed for an array can vary depending on the compiler being used. Different compilers may have different limits on the number of dimensions allowed for an array. Therefore, the maximum number of dimensions an array can have in C language cannot be determined universally and is determined by the specific compiler being used.

    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 (10/3) evaluates to 3.3333, and when multiplied by 3, it becomes 9.9999. The expression 5%3 evaluates to 2, as it gives the remainder when 5 is divided by 3. Adding these two results together, we get 9.9999 + 2 = 11. Therefore, the result of the expression is 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 given program initializes an array 'c' with 10 elements and assigns values from 1 to 10. It then uses a for loop to iterate through each element of the array and adds it to the variable 'b'. Finally, it prints the value of 'b', which is 45. 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 and assigns the values 3, 3, and 3 to the first three elements of the array. Since arrays in most programming languages are zero-indexed, the element at index 2 (num[2]) will have a value of 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 within double quotation marks, which is the standard way of representing a string in many 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 program contains a while loop that will continue to execute as long as the condition "I < 5" is true. However, there is no increment or change in the value of I within the loop, so the condition will always remain true. Therefore, the loop will continue indefinitely, resulting in an infinite loop. This means that the program will keep printing the value of I as 1 repeatedly without any end.

    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 function is used to copy a string from one location to another. In this case, it will copy the string "Hello" to the character array "str". The other options are incorrect. strcat() is used to concatenate two strings, printf() is used to print a formatted string, and str = "Hello" is invalid syntax as you cannot assign a string directly to a character array.

    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. Then, it enters a for loop where it 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, 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) between 0 and 10, the correct value for count is 6.

    Rate this question:

  • 34. 

    What will happen if you try to put so many values into an array during the initialization 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 so many values into an array during initialization that exceeds its size, it can lead to a possible system malfunction. This is because the array is allocated a fixed amount of memory during initialization, and if you try to store more values than the allocated memory can hold, it can cause memory corruption and potentially crash 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 C. First, the multiplication and division operations are performed from left to right. So, 3 multiplied by 4 is 12, and 12 divided by 5 is 2.4. Next, the addition and subtraction operations are performed from left to right. So, 2.4 plus 2 is 4.4, and 4.4 minus 1 is 3.4. Finally, the division operation is performed, so 7 divided by 8 is 0.875. Adding 0.875 to 3.4 gives the final result of 4.275, which is rounded down to 4. 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();` because the `getch()` function reads a single character from the keyboard and returns it, which is then assigned to the character variable `ch`. This statement ensures that the character from the keyboard is stored in the 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 variables sum and I to 0. It then enters a do-while loop where it adds the value of I to the sum and increments I by 1. This process continues until I becomes greater than 5. After the loop ends, the value of sum is printed using the printf statement. Since the loop iterates 5 times and adds the values of I (1+2+3+4+5), the output will be 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 indicates the number of elements that can be stored in the array. It determines the amount of memory allocated for the array and helps in accessing the elements of the array using their respective indices.

    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 in an array refers to the process of allocating memory for the array elements during program execution, specifically at runtime. This means that the memory for the array is allocated dynamically based on the program's needs, allowing for flexibility in the size of the array. Unlike static memory allocation, which occurs at compile time and has a fixed size, dynamic memory allocation allows for the creation of arrays whose size can be determined and modified during program execution.

    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 named "name" with a size of 5. It then uses the scanf function to read input from the user and store it in the "name" array. However, since the size of the array is only 5, it can only store up to 4 characters plus the null terminator. Therefore, when the input "Program" is given, only the first 4 characters "Prog" will be stored in the array. Finally, the printf function is used to print the contents of the "name" array, which will output "Prog".

    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 21, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Aug 19, 2019
    Quiz Created by
    Gaurabhkumar750
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.