Javatpoint Logo
Javatpoint Logo

Keywords in C

Keywords in C are reserved words that have predefined meanings and are part of the C language syntax. These keywords cannot be used as variable names, function names, or any other identifiers within the program except for their intended purpose. They are used to define the structure flow and behavior of a C program.

The compiler recognizes a defined set of keywords in the C programming language. These keywords have specialized purposes and play critical roles in establishing the logic and behavior of a program. Here are some characteristics of C keywords:

  • Reserved: The C language reserves keywords are those keywords that cannot be used as identifiers in programs. Using a keyword as a variable name or other identifier will cause a compilation error.
  • Predefined Meaning: Each keyword has a specific meaning that is assigned by the C language. These meanings are built into the C language's grammar and syntax and the compiler interprets them accordingly.
  • Specific Use: Keywords are designed for specific purposes and contexts within the C language. They define control structures, data types, flow control, and other language constructs. Attempting to use a keyword outside of its intended purpose will result in a compilation error.
  • Standardized: C language keywords are standardized across different compilers and implementations. It ensures the consistency and portability of C programs across different platforms and environments.

A list of 32 keywords in the c language is given below:

autobreakcasecharconstcontinuedefaultdo
doubleelseenumextern floatforgotoif
intlongregisterreturnshortsignedsizeofstatic
structswitchtypedefunionunsignedvoidvolatilewhile

Here is a brief explanation of each keyword in the C language along with their syntax and an example:

  • auto: This keyword declares an automatic variable with a local scope.

Syntax:

It has the following syntax:

Example:

Code:

Output:

Count: 10
Inner Count: 5
Count: 10
  • break: It is used to terminate the execution of a loop or switch statement.

Syntax:

It has the following syntax:

Code:

Output:

0 1 2 3 4
  • case: It is used in a switch statement to define different cases.

Syntax:

It has the following syntax:

Code:

Output:

You chose option 2.
  • char: This keyword is used to declare a character data type.

Syntax:

It has the following syntax:

Example:

Code:

Output:

Grade: A
  • const: It is used to declare constants, whose values cannot be modified.

Syntax:

It has the following syntax:

Code:

Output:

Max Size: 100
  • continue: It is used to skip the remaining statements in a loop and continue with the next iteration.

Syntax:

It has the following syntax:

Code:

Output:

0 1 2 3 4 6 7 8 9
  • default: It is used in a switch statement as the default case when no other cases match.

Syntax:

It has the following syntax:

Code:

Output:

Invalid choice.ax: default:
  • do: It is used to create a do-while loop, which executes a block of code repeatedly until a condition is met.

Syntax:

It has the following syntax:

Code:

Output:

0 1 2 3 4
  • double: This keyword is used to declare a double-precision floating-point data type.

Syntax:

It has the following syntax:

Example:

Code:

Output:

Pi: 3.141590
  • else: It is used in an if statement to specify the block of code to be executed when the condition is false.

Syntax:

It has the following syntax:

Code:

Output:

You are an adult.
  • enum: It is used to define an enumeration, which is a set of named values.

Syntax:

It has the following syntax:

Code:

Output:

Today is day number 1
  • extern: It is used to declare a variable or function that is defined in another file or external to the current scope.

Syntax:

It has the following syntax:

Code:

Output:

Global variable: 10
  • float: This keyword is used to declare a single-precision floating-point data type.

Syntax:

It has the following syntax:

Example:

Code:

Output:

Weight: 65.50
  • for: It is used to create a for loop, which repeatedly executes a block of code based on a specified condition.

Syntax:

It has the following syntax:

Example:

Code:

Output:

0 1 2 3 4
  • goto: It is used to transfer control to a labeled statement within the same function.

Syntax:

It has the following syntax:

Code:

Output:

0 1 2 3 4
Loop ended.
  • if: It is used to create an if statement to perform a certain action based on a condition.

Syntax:

It has the following syntax:

Code:

Output:

x is a positive number.
  • int: This keyword is used to declare an integer data type.

Syntax:

It has the following syntax:

Example:

Code:

Output:

Number: 10
  • long: This keyword is used to declare a long integer data type.

Syntax:

It has the following syntax:

Example:

Code:

Output:

Population: 1000000
  • register: It is used to declare a register variable, which suggests the compiler to store the variable in a register for faster access.

Syntax:

It has the following syntax:

Example:

Code:

Output:

Register Variable: 5
  • return: It is used to exit a function and return a value (if any) to the calling code.

Syntax:

It has the following syntax:

Code:

Output:

Square: 25
  • short: This keyword is used to declare a short integer data type.

Syntax:

It has the following syntax:

Code:

Output:

Copy code
Temperature: -10
  • signed: It is used to declare a signed data type, which can represent both positive and negative values.

Syntax:

It has the following syntax:

Example:

Code:

Output:

Balance: -100
  • sizeof: It is used to determine the size in bytes of a data type or variable.

Syntax:

It has the following syntax:

Code:

Output:

Size of int: 4 bytes
  • static: It is used to declare a variable or function that retains its value or scope even after the block in which it is defined has exited.

Syntax:

It has the following syntax:

Code:

Output:

Count: 1
Count: 2
  • struct: It is used to define a user-defined data type called a structure, which can hold multiple variables of different data types.

Syntax:

It has the following syntax:

Code:

Output:

Name: John, Age: 20
  • switch: It is used to create a switch statement, which allows multiple execution paths based on different cases.

Syntax:

It has the following syntax:

Code:

Output:

You chose option 2.
  • typedef: It is used to create a new name (alias) for an existing data type.

Syntax:

It has the following syntax:

Code:

Code:

Math Marks: 95
  • union: It is used to define a user-defined data type called a union, which can hold different data types but only one member at a time.

Code:

Output:

Integer: 10
  • unsigned: It is used to declare an unsigned data type, which can represent only positive

Syntax:

It has the following syntax:

Code:

Output:

Count: 100
  • void: This keyword is used to indicate the absence of a specific type or to define functions that do not return a value.

Syntax:

It has the following syntax:

Code:

Output:

Hello, World!
  • volatile: It is used to declare a variable that can be modified externally and should not be optimized by the compiler.

Syntax:

It has the following syntax:

Example:

Code:

Output:

Sensor Reading: 0
Sensor Reading: 1
Sensor Reading: 2
Sensor Reading: 3
Sensor Reading: 4
Sensor Reading: 5
Sensor Reading: 6
Sensor Reading: 7
Sensor Reading: 8
Sensor Reading: 9
  • while: It is used to create a while loop, which repeatedly executes a block of code based on a specified condition.

Syntax:

It has the following syntax:

Code:

Output:

0 1 2 3 4

Next TopicC Identifiers



Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA