C Programming Practice - Test 2

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 Nchaudhuri31
N
Nchaudhuri31
Community Contributor
Quizzes Created: 19 | Total Attempts: 8,899
Questions: 20 | Attempts: 282

SettingsSettingsSettings
C Programming Practice - Test 2 - Quiz

. Dear Learner,
This Assessment consists of questions to test your understanding on - Basics of C Programming Language
You may attempt the same and clarify doubts in WP Group. / With your Faculty Member
Regards,
Team SHIVAM


Questions and Answers
  • 1. 

    Which of the following is a keyword used for a storage class?

    • A.

      printf

    • B.

      External

    • C.

      Auto

    • D.

      Scan

    Correct Answer
    C. Auto
    Explanation
    The keyword "auto" is used for a storage class in programming. It is used to declare a local variable within a function, which automatically gets allocated and deallocated memory when the function is called and finished executing. This keyword is used to define variables that have a local scope and are automatically initialized to garbage values.

    Rate this question:

  • 2. 

    The minimum and maximum number that can be represented by int type variable are respectively

    • A.

      −32767 to +32768

    • B.

      −32767 to +32767

    • C.

      −32768 to +32768

    • D.

      −32768 to +32767

    Correct Answer
    D. −32768 to +32767
    Explanation
    The correct answer is −32768 to +32767. This is because an int type variable in most programming languages uses 2 bytes of memory, allowing it to store values from -32768 to +32767. The range starts at -32768 because one of the bits is used to represent the sign of the number. The range ends at +32767 because the remaining 15 bits are used to represent the magnitude of the number, which allows for a maximum value of 2^15 - 1.

    Rate this question:

  • 3. 

    Which operator has the lowest priority?

    • A.

      ++

    • B.

      %

    • C.

      +

    • D.

      II

    Correct Answer
    A. ++
    Explanation
    The operator with the lowest priority is ++. This is because ++ is a unary operator and it has the highest precedence among unary operators, but it has lower precedence compared to other operators like % and +.

    Rate this question:

  • 4. 

    The conversion character corresponding to hexadecimal integer is

    • A.

      %d

    • B.

      %x

    • C.

      %h

    • D.

      %hd

    Correct Answer
    D. %hd
    Explanation
    The conversion character %hd is the correct answer because it is used to format and print a signed short integer in hexadecimal format. The "h" in %hd represents the "short" data type, which is a 2-byte integer. The "d" in %hd indicates that the integer should be printed in hexadecimal format.

    Rate this question:

  • 5. 

    By default a function returns a value of type

    • A.

      Int

    • B.

      Char

    • C.

      Void

    • D.

      None of these

    Correct Answer
    A. Int
    Explanation
    By default, a function in many programming languages, including C and C++, returns a value of type int. This means that when a function is called, it will perform its operations and then return an integer value as its result. However, it is also possible for a function to have a return type of char or void, depending on the specific requirements of the program. In this case, the correct answer is int, indicating that the default return type of a function is an integer.

    Rate this question:

  • 6. 

    What will be the output of the following C code? void main() { int a; a=−8%−11; printf("%d",a); }

    • A.

      1

    • B.

      8

    • C.

      -8

    Correct Answer
    C. -8
    Explanation
    The code calculates the remainder when -8 is divided by -11 using the modulus operator (%). Since -8 divided by -11 is -1 with a remainder of -8, the output of the code will be -8.

    Rate this question:

  • 7. 

    C is a _______________ language

    • A.

      High Level

    • B.

      Low Level

    • C.

      Middle Level

    • D.

      Machine Level

    Correct Answer
    A. High Level
    Explanation
    The correct answer is "High Level." This means that the language C is designed to be user-friendly and abstracted from the underlying hardware. It provides a higher level of abstraction compared to low-level languages like assembly or machine code, making it easier for programmers to write and understand code.

    Rate this question:

  • 8. 

    What will be the output of the following C code? void main() { int a; a=5/−2; printf("%d",a); }

    • A.

      2

    • B.

      2.500000

    • C.

      -2

    • D.

      −2.500000

    Correct Answer
    C. -2
    Explanation
    The code snippet calculates the value of "a" by dividing 5 by -2. In C, integer division truncates any decimal places and only returns the whole number part. Therefore, the result of 5 divided by -2 is -2. The printf statement then prints the value of "a", which is -2.

    Rate this question:

  • 9. 

    Which of the following is not a character constant?

    • A.

      “Thank you “

    • B.

      “IT learning at its Best”

    • C.

      “23.56e-03”

    • D.

      All of the above

    Correct Answer
    D. All of the above
  • 10. 

    What will be the output of the following C code? void main() { float b; a=5.0%2; printf("%f",b); }

    • A.

      1

    • B.

      0

    • C.

      8

    • D.

      Compilation Error

    Correct Answer
    D. Compilation Error
    Explanation
    The code will result in a compilation error because the variable "a" is not declared before it is used.

    Rate this question:

  • 11. 

    What will be the output of the following C code? void main() { int a=2, b; b=a++*++a; printf("a=%d,b=%d",a,b); }

    • A.

      a=4, b=9

    • B.

      A=4, b=6

    • C.

      A=3, b=9

    • D.

      A=3,b=6

    Correct Answer
    A. a=4, b=9
    Explanation
    In the given code, the value of 'a' is initially 2. The expression 'a++' is post-increment, so the value of 'a' is used first and then incremented by 1. The expression '++a' is pre-increment, so the value of 'a' is incremented by 1 first and then used in the expression. Therefore, the value of 'b' will be 2 * 3 = 6. After the expression is evaluated, the value of 'a' becomes 4. So, the final output will be "a=4, b=6".

    Rate this question:

  • 12. 

    What will be the output of the following C code? void main() { int a=4; printf("%d %d %d”, ++a, a, a++); }

    • A.

      654

    • B.

      456

    • C.

      556

    • D.

      655

    Correct Answer
    A. 654
    Explanation
    The output of the given code will be 654. This is because the expression `++a` increments the value of `a` before it is printed, so `a` becomes 5. Then, when `a` is printed again, it is still 5. Finally, the expression `a++` increments the value of `a` after it is printed, so it becomes 6 but is not printed. Therefore, the output is 654.

    Rate this question:

  • 13. 

    What will be the output of the following C code? void main() { int a=2; a=++a*a++*++a; printf("a=%d”,a); }

    • A.

      A=65

    • B.

      A=9

    • C.

      A=17

    • D.

      Compilation Error

    Correct Answer
    A. A=65
    Explanation
    In the given code, the expression `++a*a++*++a` is evaluated. The order of evaluation is from left to right. Initially, `a` is 2.

    First, `++a` increments `a` to 3. Then, `a` is multiplied by `a++`. The value of `a` is now 3, so the result is 3 * 3 = 9.

    Next, `a` is incremented again to 4. Finally, `a` is multiplied by `++a`, which is now 4. The result is 4 * 4 = 16.

    Therefore, the value of `a` is 16. The correct answer is a=16.

    Rate this question:

  • 14. 

    What will be the output of the following C code? void main() { int i = 1; printf(“%d %d %d”,i++,i,++i); }

    • A.

      1 2 3

    • B.

      2 2 2

    • C.

      3 2 2

    • D.

      Compilation Error

    Correct Answer
    B. 2 2 2
    Explanation
    The output of the code will be "2 2 2". This is because the order of evaluation of the arguments in the printf statement is not guaranteed in C. In this case, the order in which the arguments are evaluated is undefined behavior. Therefore, the values of i can be different at different points during the evaluation, leading to inconsistent results.

    Rate this question:

  • 15. 

    What will be the output of the following C code? void main() { int i; i = −1 < 20 >100; printf(“%d”,i); }

    • A.

      0

    • B.

      1

    • C.

      Garbage value

    • D.

      Compilation Error

    Correct Answer
    A. 0
    Explanation
    In the given code, the expression "-1 < 20" is evaluated first. This expression is true because -1 is less than 20. The result of this expression is 1. Then, the expression "1 > 100" is evaluated. This expression is false because 1 is not greater than 100. The result of this expression is 0. Therefore, the value of i is 0. When the value of i is printed using printf, the output will be 0.

    Rate this question:

  • 16. 

    What will be the output of the following C code? void main() { unsigned int a=1; printf(“%d”,a

    • A.

      0

    • B.

      1

    • C.

      Garbage value

    • D.

      Compilation Error

    Correct Answer
    A. 0
    Explanation
    The output of the given C code will be 0. The code initializes an unsigned integer variable 'a' with the value 1. In the printf statement, the expression 'a

    Rate this question:

  • 17. 

    What will be the output of the following C code? void main() { int i; i = 3^2; printf(“%d”,i); }

    • A.

      9

    • B.

      0

    • C.

      Garbage value

    • D.

      1

    Correct Answer
    D. 1
    Explanation
    The code uses the bitwise XOR operator (^) to perform an operation on the numbers 3 and 2. The XOR operator compares the binary representation of the two numbers and returns a new number with bits set where the corresponding bits of the two numbers are different. In this case, 3 is represented as 0011 in binary and 2 is represented as 0010. The XOR operation will result in 0001, which is equivalent to 1 in decimal. Therefore, the output of the code will be 1.

    Rate this question:

  • 18. 

    What will be the output of the following C code? void main() { int i; i = !5; printf(“%d”,i); }

    • A.

      0

    • B.

      -5

    • C.

      Garbage value

    • D.

      Compilation Error

    Correct Answer
    A. 0
    Explanation
    The code snippet initializes the variable 'i' with the logical negation of the value 5. In C, any non-zero value is considered as true, and the logical negation of true is false, which is represented by the value 0. Therefore, the output of the code will be 0.

    Rate this question:

  • 19. 

    What will be the output of the following C code? void main() { int i; i = !−5; printf(“%d”,i); }

    • A.

      5

    • B.

      Garbage value

    • C.

      Compilation Error

    Explanation
    The output of the given code will be 1. In the code, the variable i is assigned the value of the logical NOT operator applied to -5. The logical NOT operator returns 0 if the operand is non-zero and 1 if the operand is zero. Since -5 is non-zero, the logical NOT operator returns 0, which is then assigned to i. When the value of i is printed using the printf() function, it will display 0.

    Rate this question:

  • 20. 

    What will be the output of the following C code? void main() { int x, y, z; x = y = z = 1; printf(“%d”, x + y + z); }

    • A.

      1

    • B.

      3

    • C.

      Garbage value

    • D.

      Compilation Error

    Correct Answer
    B. 3
    Explanation
    The code initializes three variables, x, y, and z, to the value 1. Then, it prints the sum of these three variables, which is 3.

    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
  • Feb 17, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Jun 10, 2018
    Quiz Created by
    Nchaudhuri31
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.