What is a C identifier ?
A C identifier can be a name used to identify a variable, function, or any other user-defined item. An identifier can start with a letter A to Z, a to z, or an underscore ‘_’ followed by zero or more letters, underscores, and digits (0 to 9).
C is not allowing punctuation characters such as @, $, and % within identifiers. C is a case-sensitive programming language. Thus, hello and Hello are two different identifiers in C.
What are the naming rules for a C identifier ?
- An Identifier can contain only alphanumeric characters(a-z , A-Z , 0-9) and underscore(_).
- The first character of an identifier should be an alphabet(a-z , A-Z) or underscore (_). Means numeric (0-9)can not be used as the first character of a C identifier.
- Identifiers are case sensitive in C. For example roll and Roll are two different identifiers in C.
- Reserved keywords are not allowed to be used as Identifiers.
- No special characters, such as period, semicolon, white spaces, comma or slash are permitted to be used in or as Identifier.
What is keyword in C programming ?
Keywords are reserved words and have special meaning in C language. The specific meaning of C language keywords has already been described to the C compiler. These meaning cannot be changed. Thus, keywords cannot be used as variable names or for any other purpose because that would try to change the existing meaning of the keyword, which is not allowed. There are total 32 keywords in C language.
What is the use of white spaces in C program ?
White space is the term used in C to describe blanks, tabs, newline characters. Some times white spaces are necessary as in the case of below statement.
there must be at least one white space character (usually a space) between int and roll for the compiler to be able to distinguish them as two different tokens.
On the other hand, in the following statement −
total = no1 + no2; // add no1 and no2 and store to total
Whitespace characters are not necessary between total and = operator, or between = operator and no1 variable, although you are free to include some if you wish to increase readability. So in this case white spaces are optional.
What are the basic rules while writing a C programming Syntax or Statement ?
We have to follow these basic rules while writing a C programming Syntax or Statement.
- C is a case sensitive language means Student and student have different meaning to C.
- All C statement must end with a semicolon.
- White space is used in C normally to describe blanks and tabs.
- White space is required between keywords and identifiers.
- White space can be used for better readability.
Variables in C Programming
When we want to store any data or information, we store it in the computer’s memory. But we do not remember the memory locations. We simply remember the name of files. The operating system knows in which memory location that file was stored.so that it becomes easier for us to find it and access it.
Similarly, in C language, when we want to use some data value in our program, we can store it in a memory space and name it so that further we can access it easily.
So a variable in simple terms can be defined as a named storage space which has some memory allocated to it. As its name suggests it has the ability to change its value. Means we can change the value of this named memory location when ever needed.
So basically a variable is used to store some form of data. We should remember that different types of variables require different amounts of memory space in computers memory and have some specific set of operations which can be applied on them.
Single variable declaration syntax :
- datatype variable_name;
Multiple variable declaration syntax :
- datatype variable1_name, variable2_name, variable3_name;
Data type of variables
The variable can be declared as the following data type:
- char – Can store a character in it
- int – can store an integer in it
- float – A single-precision floating point value
- double – A double-precision floating point value
Variable naming rules
- The name of variables can be composed of letters, digits and underscore.
- The variable names can begin with either letter or underscore. Variable names must not start with a digit.
- spaces are not allowed in variable names.
- we can not use reserved keywords as variable names.
- C is a case sensitive language so upper and lower case letters are treated differently. So it may be suggested to keep the variable names in lower case.
Variable declaration and definition
Before using a variable in our program we must declare it. declaration tells the compiler –
(1) the name of variable
(2) what type of data the variable will hold.
Defining a variable tells the compiler to assign memory to the variable. In most cases c compiler declares and defines a variable at the same time.
Look at the below example.
// declaration and definition of variable ‘name’
char name = ‘a’;
// both declaration and definition occurs. ‘roll’ is allocated
// memory and assigned some garbage value.
// multiple declarations and definitions
int _math, _sc, _eng;
// Let us print a variable
printf(“%c \n”, name);
Before proceeding further please have a look at the below C program
For Life time valid video tutorials of this course with quiz and certification : Click Here
Downloadable video tutorials for TTRC Player : Click Here
Tag:c programming for beginners, Data type of variables, Variable declaration and definition, Variable naming rules, Variables in C Programming, What are the basic rules while writing a C programming Syntax or Statement, What are the naming rules for a C identifier, What is a C identifier, What is keyword in C programming, What is the use of white spaces in C program