C Programming Language: Test Your Skills! Trivia 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 Pranay573
P
Pranay573
Community Contributor
Quizzes Created: 4 | Total Attempts: 16,247
Questions: 30 | Attempts: 104

SettingsSettingsSettings
C Programming Language: Test Your Skills! Trivia Quiz - Quiz

Are you looking to test your skills when it comes to the C programming language? This is the most popular language when it comes to writing operating software due to its flexibility and easy to use. The name from this application came up as a result of it coming after the B language. See how good you are in using it by taking this quiz.


Questions and Answers
  • 1. 

    Point out the correct statements are correct about the program below? #include<stdio.h> int main() { char ch; while(x=0;x<=255;x++) printf("ASCII value of %d character %c\n", x, x); return 0; }

    • A.

      The code generates an infinite loop

    • B.

      The code prints all ASCII values and its characters

    • C.

      Error: x undeclared identifier

    • D.

      Error: while statement missing

    Correct Answer
    D. Error: while statement missing
    Explanation
    The given code has a syntax error as the while statement is missing its condition. This causes a compilation error.

    Rate this question:

  • 2. 

    Which of the following is the correct usage of conditional operators used in C?

    • A.

      A>b ? c=30 : c=40;

    • B.

      A>b ? c=30;

    • C.

      Max = a>b ? a>c?a:c:b>c?b:c

    • D.

      Return (a>b)?(a:b)

    Correct Answer
    C. Max = a>b ? a>c?a:c:b>c?b:c
    Explanation
    The correct usage of conditional operators in C is demonstrated in the fourth option: "return (a>b)?(a:b)". This statement uses the ternary operator to check if "a" is greater than "b". If it is true, the expression returns the value of "a", otherwise it returns the value of "b".

    Rate this question:

  • 3. 

    What will be the output of the program? #include<stdio.h> #include<math.h> int main() { float n=1.54; printf("%f, %f\n", ceil(n), floor(n)); return 0; }

    • A.

      2.000000, 1.000000

    • B.

      1.500000, 1.500000

    • C.

      1.550000, 2.000000

    • D.

      1.000000, 2.000000

    Correct Answer
    A. 2.000000, 1.000000
    Explanation
    The program uses the ceil() and floor() functions from the math.h library to find the ceiling and floor values of the variable n. The ceil() function returns the smallest integer greater than or equal to n, while the floor() function returns the largest integer less than or equal to n. In this case, the variable n has a value of 1.54. The ceil() function will round this up to 2.000000, while the floor() function will round it down to 1.000000. Therefore, the output of the program will be "2.000000, 1.000000".

    Rate this question:

  • 4. 

    What will be the output of the program? #include<stdio.h> int main() { float d=2.25; printf("%e,", d); printf("%f,", d); printf("%g,", d); printf("%lf", d); return 0; }

    • A.

      2.2, 2.50, 2.50, 2.5

    • B.

      2.2e, 2.25f, 2.00, 2.25

    • C.

      2.250000e+000, 2.250000, 2.25, 2.250000

    • D.

      Error

    Correct Answer
    C. 2.250000e+000, 2.250000, 2.25, 2.250000
    Explanation
    The program will output the value of the variable "d" in different formats.

    The first printf statement will output the value of "d" in scientific notation with 6 decimal places, resulting in "2.250000e+000".

    The second printf statement will output the value of "d" as a floating-point number with 2 decimal places, resulting in "2.25".

    The third printf statement will output the value of "d" in either scientific notation or decimal notation, depending on the magnitude of the number. Since "d" is relatively small, it will be outputted in decimal notation with 2 decimal places, resulting in "2.25".

    The fourth printf statement will output the value of "d" as a double-precision floating-point number with 6 decimal places, resulting in "2.250000".

    Therefore, the correct answer is "2.250000e+000, 2.250000, 2.25, 2.250000".

    Rate this question:

  • 5. 

    Point out the error in the program #include<stdio.h> int main() { int i; #if A printf("Enter any number:"); scanf("%d", &i); #elif B printf("The number is odd"); return 0; }

    • A.

      Error: unexpected end of file because there is no matching #endif

    • B.

      The number is odd

    • C.

      Garbage values

    • D.

      None of above

    Correct Answer
    A. Error: unexpected end of file because there is no matching #endif
    Explanation
    The error in the program is that there is no matching #endif for the #if directive. This causes an unexpected end of file error.

    Rate this question:

  • 6. 

    If a function contains two return statements successively, the compiler will generate warnings.

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    When a function contains two return statements successively, it means that both of these return statements will be executed. This can lead to unexpected behavior, as only the first return statement encountered will be executed, and the second return statement will be ignored. This can cause confusion and potential bugs in the code. Therefore, the compiler will generate warnings to alert the programmer about this potential issue.

    Rate this question:

  • 7. 

    What will be the output of the program ? #include<stdio.h> int main() { float arr[] = {12.4, 2.3, 4.5, 6.7}; printf("%d\n", sizeof(arr)/sizeof(arr[0])); return 0; }

    • A.

      5

    • B.

      4

    • C.

      6

    • D.

      7

    Correct Answer
    B. 4
    Explanation
    The program declares an array of type float with 4 elements. The sizeof operator is used to determine the size of the array in bytes and is divided by the size of each element in the array. Since each element is of type float, which typically occupies 4 bytes in memory, the result is 16/4 = 4. Therefore, the output of the program will be 4.

    Rate this question:

  • 8. 

    Which of the following statements correct about the below program? #include<stdio.h> int main() { union a { int i; char ch[2]; }; union a u1 = {512}; union a u2 = {0, 2}; return 0; } 1: u2 CANNOT be initialized as shown. 2: u1 can be initialized as shown. 3: To initialize char ch[] of u2 '.' operator should be used. 4: The code causes an error 'Declaration syntax error'

    • A.

      1,2

    • B.

      2,3

    • C.

      1,2,3

    • D.

      2,4

    Correct Answer
    C. 1,2,3
    Explanation
    1. The statement "u2 CANNOT be initialized as shown" is correct because the initialization of u2 with {0, 2} is valid and allowed.
    2. The statement "u1 can be initialized as shown" is correct because the initialization of u1 with {512} is valid and allowed.
    3. The statement "To initialize char ch[] of u2 '.' operator should be used" is correct because the initialization of char ch[] in u2 should use the '.' operator instead of a comma.

    Rate this question:

  • 9. 

    Is there any difference int the following declarations? int fun(int arr[]); int fun(int arr[2]);

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    There is no difference in the two declarations. Both declarations are for a function named "fun" that takes an integer array as a parameter. The size of the array is not specified in either declaration. Therefore, the correct answer is False.

    Rate this question:

  • 10. 

    What will be the output of the program? #include<stdio.h> int get(); int main() { const int x = get(); printf("%d", x); return 0; } int get() { return 20; }

    • A.

      Garbage value

    • B.

      20

    • C.

      Error

    • D.

      0

    Correct Answer
    B. 20
    Explanation
    The program defines a function `get()` that returns the value 20. In the `main()` function, the value returned by `get()` is assigned to the constant variable `x`. Then, the value of `x` is printed using `printf()`. Since the value returned by `get()` is 20, the output of the program will be 20.

    Rate this question:

  • 11. 

    Does there exist any way to make the command-line arguments available to other functions without passing them as arguments to the function?

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    Yes, there exists a way to make the command-line arguments available to other functions without passing them as arguments to the function. This can be achieved by declaring the command-line arguments as global variables, which allows them to be accessed by any function within the program. However, it is generally considered a better practice to pass the arguments as parameters to the functions that require them, as it promotes better code organization and reusability.

    Rate this question:

  • 12. 

    Point out the error in the program. #include<stdio.h> #include<stdlib.h> int fun(const union employee *e); union employee { char name[15]; int age; float salary; }; const union employee e1; int main() { strcpy(e1.name, "A"); fun(&e1); printf("%s %d %f", e1.name, e1.age, e1.salary); return 0; } int fun(const union employee *e) { strcpy((*e).name, "B"); return 0; }

    • A.

      Error: RValue required

    • B.

      Error: cannot convert parameter 1 from 'const char[15]' to 'char *'

    • C.

      Error: LValue required in strcpy

    • D.

      No error

    Correct Answer
    B. Error: cannot convert parameter 1 from 'const char[15]' to 'char *'
    Explanation
    The error in the program is that the function `fun` is trying to modify the value of a constant union employee object. The parameter `e` is declared as a pointer to a constant union employee, which means that the function is not allowed to modify the object it points to. However, inside the function, `strcpy` is used to modify the `name` member of the union employee object, which is not allowed. This results in the error "cannot convert parameter 1 from 'const char[15]' to 'char *'".

    Rate this question:

  • 13. 

    What function should be used to free the memory allocated by calloc() ?

    • A.

      Dealloc();

    • B.

      Malloc(variable_name, 0)

    • C.

      Free();

    • D.

      Memalloc(variable_name, 0)

    Correct Answer
    C. Free();
    Explanation
    The correct answer is "free();". The function "free()" is used to deallocate the memory that was previously allocated using functions like calloc(), malloc(), or realloc(). It releases the memory back to the operating system, making it available for other programs or processes to use.

    Rate this question:

  • 14. 

    Point out the correct statement which correctly free the memory pointed to by 's' and 'p' in the following program? #include<stdio.h> #include<stdlib.h> int main() { struct ex { int i; float j; char *s }; struct ex *p; p = (struct ex *)malloc(sizeof(struct ex)); p->s = (char*)malloc(20); return 0; }

    • A.

      Free(p); , free(p->s);

    • B.

      free(p->s); , free(p);

    • C.

      Free(p->s);

    • D.

      Free(p);

    Correct Answer
    B. free(p->s); , free(p);
    Explanation
    The correct statement to free the memory pointed to by 's' and 'p' in the given program is "free(p->s); , free(p);". This is because 'p' is a pointer to a struct 'ex' and 's' is a pointer to a character array within the struct. Therefore, we need to free the memory allocated for 's' before freeing the memory allocated for the entire struct 'ex'.

    Rate this question:

  • 15. 

    What do the following declaration signify? void *cmp();

    • A.

      Cmp is a pointer to an void type.

    • B.

      Cmp is a void type pointer variable.

    • C.

      Cmp is a function that return a void pointer.

    • D.

      Cmp function returns nothing.

    Correct Answer
    C. Cmp is a function that return a void pointer.
    Explanation
    The given declaration "void *cmp();" signifies that cmp is a function that returns a void pointer. The void * return type indicates that the function can return a pointer to any data type, as the void pointer can be implicitly converted to any other pointer type.

    Rate this question:

  • 16. 

    What will be the output of the program? #include<stdio.h> int main() { char huge *near *far *ptr1; char near *far *huge *ptr2; char far *huge *near *ptr3; printf("%d, %d, %d\n", sizeof(**ptr1), sizeof(ptr2), sizeof(*ptr3)); return 0; }

    • A.

      4,4,4

    • B.

      2,2,2

    • C.

      2,4,8

    • D.

      2,8,4

    Correct Answer
    A. 4,4,4
    Explanation
    The program declares three pointer variables of different types: ptr1, ptr2, and ptr3. The sizeof operator is then used to determine the size of the objects that the pointers point to.

    In the case of **ptr1, ptr1 is a pointer to a pointer to a character. The sizeof(**ptr1) gives the size of the character, which is typically 1 byte.

    For ptr2, it is a pointer to a far pointer to a near pointer to a character. The sizeof(ptr2) gives the size of the far pointer, which is typically 4 bytes on a 32-bit system.

    Lastly, ptr3 is a pointer to a near pointer to a far pointer to a character. The sizeof(*ptr3) gives the size of the near pointer, which is typically 4 bytes on a 32-bit system.

    Therefore, the output of the program will be 4, 4, 4.

    Rate this question:

  • 17. 

    Point out the error in the following program. #include<stdio.h> void display(int (*ff)()); int main() { int show(); int (*f)(); f = show; display(f); return 0; } void display(int (*ff)()) { (*ff)(); } int show() { printf("c-skills"); }

    • A.

      Error: invalid parameter in function display()

    • B.

      Error: invalid function call f=show;

    • C.

      No error and prints "c-skills"

    • D.

      None

    Correct Answer
    C. No error and prints "c-skills"
    Explanation
    The program does not have any errors and will print "c-skills". The function display() takes a function pointer as a parameter and calls the function using the pointer. The function show() is defined correctly and will print "c-skills" when called. The function pointer f is assigned the address of the show() function and is passed to the display() function. Therefore, there are no errors and the program will execute successfully.

    Rate this question:

  • 18. 

    Which of the following function sets first n characters of a string to a given character?

    • A.

      Strinit()

    • B.

      Strnset()

    • C.

      Strset()

    • D.

      Strcset()

    Correct Answer
    B. Strnset()
    Explanation
    The function strnset() sets the first n characters of a string to a given character. This means that it replaces the characters in the specified range with the given character, effectively initializing the string with the specified character for the specified number of characters.

    Rate this question:

  • 19. 

    We can modify the pointers "source" as well as "target".

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    The statement is true because it states that we can modify the pointers "source" and "target". This implies that we have the ability to change the values or properties of these pointers in some way.

    Rate this question:

  • 20. 

    Will the program outputs "users-choice.blogspot.com"? #include<stdio.h> #include<string.h> int main() { char str1[] = "users-choice.blogspot.com"; char str2[20]; strncpy(str2, str1, 8); printf("%s", str2); return 0; }

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    The program will output "users-cho" because the strncpy function is used to copy the first 8 characters of str1 into str2. Therefore, str2 will contain "users-cho" and this will be printed using the printf function.

    Rate this question:

  • 21. 

    Can we use a switch statement to switch on strings?

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    Switch statements in most programming languages cannot directly switch on strings. They typically only allow switching on integer or character values. To switch on strings, we usually need to use if-else statements or other conditional constructs.

    Rate this question:

  • 22. 

    Is it true that too many recursive calls may result into stack overflow?

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    Yes, it is true that too many recursive calls may result in a stack overflow. When a recursive function is called, the current state of the function is pushed onto the call stack. If the number of recursive calls is too large, the call stack can run out of space, resulting in a stack overflow error. This can happen when the base case of the recursion is not reached or when the recursive calls are not properly managed.

    Rate this question:

  • 23. 

    A macro must always be defined in capital letters.

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    There is no requirement for macros to be defined in capital letters. Macros can be defined using any combination of uppercase and lowercase letters.

    Rate this question:

  • 24. 

    In a macro call the control is passed to the macro.

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    In a macro call, the control is not passed to the macro. Instead, the macro is expanded inline at the location where it is called. This means that the code inside the macro is executed at the location of the macro call, and then the program continues from where it left off. So, the statement is false.

    Rate this question:

  • 25. 

    A header file contains macros, structure declaration and function prototypes.

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    A header file is a file that contains declarations and definitions that can be shared across multiple source code files in a program. It typically includes macros, structure declarations, and function prototypes. These declarations and definitions allow the source code files to access and use the macros, structures, and functions defined in the header file. Therefore, the statement "A header file contains macros, structure declaration and function prototypes" is true.

    Rate this question:

  • 26. 

    Input/output function prototypes and macros are defined in which header file?

    • A.

      Conio.h

    • B.

      Stdlib.h

    • C.

      Stdio.h

    • D.

      Dos.h

    Correct Answer
    C. Stdio.h
    Explanation
    The header file "stdio.h" contains the function prototypes and macros for input/output operations in C. It includes functions like printf(), scanf(), and macros like EOF and NULL.

    Rate this question:

  • 27. 

    The keyword used to transfer control from a function back to the calling function is

    • A.

      Goto

    • B.

      Return

    • C.

      Break

    • D.

      None

    Correct Answer
    B. Return
    Explanation
    The keyword "return" is used to transfer control from a function back to the calling function. When a function is called, it executes its code and may produce a result. The "return" keyword allows the function to return this result to the calling function and terminate its execution. This allows the calling function to continue its execution using the returned result or perform any necessary actions based on the returned value.

    Rate this question:

  • 28. 

    The library function used to find the last occurrence of a character in a string is

    • A.

      Strnstr()

    • B.

      Laststr()

    • C.

      Strrchr()

    • D.

      Strstr()

    Correct Answer
    C. Strrchr()
    Explanation
    The strrchr() function is used to find the last occurrence of a character in a string. It takes two arguments - the string in which to search for the character, and the character to be found. The function returns a pointer to the last occurrence of the character in the string, or NULL if the character is not found. This function is commonly used in C programming to search for specific characters in a string and manipulate the string accordingly.

    Rate this question:

  • 29. 

    Which header file should you include, if you are going to develop a function, which can accept variable number of arguments?

    • A.

      Varagrg.h

    • B.

      Stdlib.h

    • C.

      Stdio.h

    • D.

      Stdarg.h

    Correct Answer
    D. Stdarg.h
    Explanation
    The correct answer is stdarg.h. This header file should be included if you are going to develop a function that can accept a variable number of arguments. The stdarg.h header file provides the necessary macros and types for implementing functions with variable arguments.

    Rate this question:

  • 30. 

    Bit fields CANNOT be used in union.

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    Bit fields can be used in unions. In a union, different members share the same memory space, and using bit fields allows for efficient use of memory by packing multiple variables within a single memory location. Therefore, the statement that bit fields cannot be used in unions is false.

    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 19, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Sep 23, 2011
    Quiz Created by
    Pranay573
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.