Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

C Identifiers

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

C Identifiers

Identifier refers to name given to entities such as variables, functions, structures etc.

Identifiers must be unique. They are created to give a unique name to an entity to identify it during the execution of the
program. For example:

Here, money and accountBalance are identifiers.

Also remember, identifier names must be different from keywords. You cannot use int as an identifier because int is a
keyword.

Rules for naming identifiers

1. A valid identifier can have letters (both uppercase and lowercase letters), digits and underscores.

2. The first letter of an identifier should be either a letter or an underscore.

3. You cannot use keywords like int, while etc. as identifiers.

4. There is no rule on how long an identifier can be. However, you may run into problems in some compilers if the
identifier is longer than 31 characters.

You can choose any name as an identifier if you follow the above rule, however, give meaningful names to identifiers that
make sense.

Literals

Literals are data used for representing fixed values. They can be used directly in the code. For example: 1, 2.5, 'c' etc.

Here, 1, 2.5 and 'c' are literals. Why? You cannot assign different values to these terms.

In C programming, octal starts with a 0, and hexadecimal starts with a 0x.

Constants

If you want to define a variable whose value cannot be changed, you can use the const keyword. This will create a constant.
For example,

const double PI = 3.14;

Notice, we have added keyword const.

Here, PI is a symbolic constant; its value cannot be changed.

const double PI = 3.14;

PI = 2.9; //Error

You can also define a constant using the #define preprocessor directive.
void

void is an incomplete type. It means "nothing" or "no type". You can think of void as absent.

For example, if a function is not returning anything, its return type should be void.

Note that, you cannot create variables of void type.

signed and unsigned

In C, signed and unsigned are type modifiers. You can alter the data storage of a data type by using them:

 signed - allows for storage of both positive and negative numbers

 unsigned - allows for storage of only positive numbers

Derived Data Types

Data types that are derived from fundamental data types are derived types. For example: arrays, pointers, function types,
structures, etc.

How does this program work?

 All valid C programs must contain the main() function. The code execution begins from the start of
the main() function.

 The printf() is a library function to send formatted output to the screen. The function prints the string inside
quotations.

 To use printf() in our program, we need to include stdio.h header file using the #include <stdio.h> statement.

 The return 0; statement inside the main() function is the "Exit status" of the program. It's optional.

When a character is entered by the user in the above program, the character itself is not stored. Instead, an integer value
(ASCII value) is stored.
And when we display that value using %c text format, the entered character is displayed. If we use %d to display the
character, it's ASCII value is printed.

C Bitwise Operators

During computation, mathematical operations like: addition, subtraction, multiplication, division, etc are converted to bit-
level which makes processing faster and saves power.

You might also like