Which one is not a reserved keyword in C language

Which one is not a reserved keyword in C language

A) auto

B) case

C) main

D) default

E) register

The correct answer to the question “Which one is not a reserved keyword in C language?” is option(C) Main.

Explanation:

main is not a reserved keyword in C. It is a special function used in the program. While the C language standard requires a main function for the program to run, you are free to name it anything. However, it’s strongly recommended to use the main keyword as the entry point.

Table of contents :

Reserved Keywords in C

In C programming, keywords are predefined reserved words that have specific meanings and define the behavior of various constructs in the language. Keywords cannot be used as variables or function names. Let’s go through the reserved keywords in the C language:

1. Auto Keyword in C

The keyword auto is a storage class specifier that declares the local variable with automatic storage by default. The auto keyword was originally used to declare variables that have automatic storage duration. It’s not necessary to use auto keyword in modern code but it still remains a reserved keyword in C. Please do note that the auto keyword is not supported in C (prior to C11). Let’s see how we can work assign automatic storage:

Example :

#include <stdio.h>
void function() {
    int x = 10;  // Declare x as an integer, no need for 'auto'
    printf("x = %d\n", x);
}

int main() {
    function();
    return 0;
}

Output:

Auto Keyword in C output

In this example, x will have automatic storage duration by default, given that theauto keyword has not been utilized.

2. Case Keyword in C

Case is a reserved keyword in C. It is used within a switch statement to define a branch of code that will execute if a particular value of the switch expression matches a specified constant value.

The switch keyword begins the switch statement, the case keyword defines each branch, and the default keyword specifies what happens if no case matches.

Case Keyword in C Output
  • The switch keyword starts the switch statement.
  • The case keyword defines an execution by following a constant value.
  • The break keyword exits the switch block.
  • The default keyword executes if no case constant matches the expression.

Example:

#include <stdio.h>
int main() {
    int x = 2; 
    switch (x) {
        case 1:
            printf("x is 1\n");
            break;
        case 2:
            printf("x is 2\n");
            break;
        default:
            printf("x is neither 1 nor 2\n");
    }

    return 0;
}

Output:

Example Output

In this example, case allows the program to branch to specific blocks of code based on the value of x. Each case corresponds to a specific value and returns the block if the value matches.

3. Default Keyword  in C

Default is a reserved keyword in C. The keyword is used in switch statements to specify the default block of code that runs if no matching case is found.

  • The switch keyword starts the switch statement.
  • The case keyword defines an execution by following a constant value.
  • The break keyword exits the switch block.
  • The default keyword executes if no case constant matches the expression.

Example:

#include <stdio.h>

int main() {

    int x = 9;

    switch (x) {

        case 1:

            printf("x is 1\n");

            break;

        case 2:

            printf("x is 2\n");

            break;

        default:

            printf("x is neither 1 nor 2\n");

    }

    return 0;

}

Output:

Default Keyword  in C Output

In this example, default allows the program to branch to specific blocks of code based on the value of x. If no case matches the specific value then it returns the default case.

4. Register Keyword  in C

Register is a reserved keyword in C. It suggests that a variable should be stored in a CPU rather than in memory for faster access. Modern compilers generally ignore this and handle optimizations themselves, as they can handle it better than an individual.

Example:

#include <stdio.h>

int main() {

    register int i;

    for (i = 0; i < 5; i++) {

        printf("i = %d\n", i);

    }

    return 0;

}

Output:

Register Keyword  in C Output

register int i declares the variable i as a register variable, suggesting to the compiler to store it in a register for faster access.

Conclusion

In conclusion, main is not a reserved keyword in C; it is simply the entry point of a program. All other options auto, case, default, and register are reserved keywords with specific functions in C.

About the Author

Technical Research Analyst - Full Stack Development

Kislay is a Technical Research Analyst and Full Stack Developer with expertise in crafting Mobile applications from inception to deployment. Proficient in Android development, IOS development, HTML, CSS, JavaScript, React, Angular, MySQL, and MongoDB, he’s committed to enhancing user experiences through intuitive websites and advanced mobile applications.

Full Stack Developer Course Banner