C Programming Language: Test Your Skills! Trivia Quiz

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 Pranay573
P
Pranay573
Community Contributor
Quizzes Created: 4 | Total Attempts: 16,561
| Attempts: 104 | Questions: 30
Please wait...
Question 1 / 30
0 %
0/100
Score 0/100
1. A header file contains macros, structure declaration and function prototypes.

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.

Submit
Please wait...
About This Quiz
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... see moredue 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. see less

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

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.

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

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.

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

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.

Submit
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;
}

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.

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

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.

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

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.

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

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.

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

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.

Submit
10. Bit fields CANNOT be used in union.

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.

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

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.

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

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.

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

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.

Submit
14. A macro must always be defined in capital letters.

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.

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

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

Submit
16. Can we use a switch statement to switch on strings?

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.

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

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

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

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

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

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.

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

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.

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

Explanation

The given code has a syntax error as the while statement is missing its condition. This causes a compilation error.

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

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.

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

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.

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

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.

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

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.

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

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

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

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.

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

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.

Submit
29. Which of the following is the correct usage of conditional operators used in 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".

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

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.

Submit
View My Results

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

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
Cancel
  • All
    All (30)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
A header file contains macros, structure declaration and function...
Is it true that too many recursive calls may result into stack...
What will be the output of the program ? ...
What function should be used to free the memory allocated by calloc()...
Point out the error in the program ...
Input/output function prototypes and macros are defined in which...
If a function contains two return statements successively, the...
We can modify the pointers "source" as well as...
The keyword used to transfer control from a function back to the...
Bit fields CANNOT be used in union.
What will be the output of the program? ...
Does there exist any way to make the command-line arguments available...
The library function used to find the last occurrence of a character...
A macro must always be defined in capital letters.
What will be the output of the program? ...
Can we use a switch statement to switch on strings?
What will be the output of the program? ...
Point out the correct statement which correctly free the memory...
Which of the following function sets first n characters of a string to...
What do the following declaration signify? void *cmp();
Point out the correct statements are correct about the program below? ...
Which header file should you include, if you are going to develop a...
In a macro call the control is passed to the macro.
Is there any difference int the following declarations?...
What will be the output of the program? ...
Point out the error in the program. ...
Point out the error in the following program. ...
Which of the following statements correct about the below program? ...
Which of the following is the correct usage of conditional operators...
Will the program outputs "users-choice.blogspot.com"? ...
Alert!

Advertisement