Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the all-in-one-wp-security-and-firewall domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home/u956308407/domains/dipaktiwari.com/public_html/wp-includes/functions.php on line 6114

Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the wordpress-seo domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home/u956308407/domains/dipaktiwari.com/public_html/wp-includes/functions.php on line 6114
Constants variables and data types in C - Dipak Tiwari
‎Constants variables and data types in C

Constants variables and data types in C

Share this content on

Constants variables and data types in c

Like any other language, C has its own vocabulary and grammar. We will discuss the concepts of Constants variables and data types in c programming language.

Tokens

In C program collection of Keywords, Identifiers, Constants, Strings, special Symbols and Operators are called Tokens.

tokens

Keywords And Identifiers

Every single word in C program is classified as either a keyword or an identifier.

All keywords have fixed meanings and these meaning cannot be changed.

The list of keywords are listed in below table.

int
long
short
signed​
unsigned​
char​
float​
double​
const​
continue
default
do
union​
else
enum
extern
auto
break
case
switch
typedef
for
goto
if
register​
return​
sizeof
static
struct​
void
volatile
while

Identifiers

  • Identifiers refer to the names of variables, functions and array.
  • These are user-defined names.
  • It consists of a sequence of letters and digits, with a letters as a first character.
  • Uppercase and lowercase letters are allowed.
  • The underscore characters is also permitted in identifiers.

Constants

  • Constants in C refer to fixed values that do not change during the execution of a program.
  • There are main two type of constants: i) Numeric constants ii) Character constants
constants

i) Numeric constants

A. Integer Constants: An integer constants refers to a sequence of digits.

There are three types of integers decimal, octal and hexadecimal.

Decimal integers consist of set of digits, 0 through 9, preceded by an optional – or + sign.

Examples: 456

                 -253

                  0

                  98767

                  +4734

Embeded space, commas, and non-digit characters are not permitted between digits.

Examples: 65 896

                 45,7665

                  $867

All are illegal numbers.

Octal integer: consists of any combination of digits from the set 0 through 7, with a leading 0.

Examples: 045

                 0

                 0768

Hexadecimal integer: A sequence of digits preceded by 0x or 0X is considered as hexadecimal ineteger. They may also include alphabets A through F or f. The letters A through F represent the numbers 10 through 15.

Examples:

                   0X5

                   0X76F

                   0xbcd

B. Real Constants: Quantities are represented by numbers containing fractional parts are called real or floating point constants.

Examples: 0.0056

                  +34.675

                  -53.46

                   -0.89

It is possible to omit digits before the decimal points, or digits after decimal point.

Examples: +.467

                   634.

                   -.53

An real number may also be written in exponential or scintific notation. The value 534.89 may be written as 5.3489e2 in an exponential notation.

ii) Character constants: 

A. Single character constants: Contains a single character enclosed within a pair of single quote marks.

Examples: ‘d’     ‘7’      ‘T’  ‘;’   ”

Note that the character constant ‘7’ is not the same as the number 7. The last constant is a blank space.

Character constants have integer values know as ASCII values. For example,

printf(“%d”,’a’);

would print the number 97, the ASCII value of the letter a. Similarly, the statement

printf(“%c”,97);

would print the letter ‘a’.

B. String constants: is a sequence of characters enclosed in double quotes.

The characters may be letters, numbers, special characters and blank space.

Examples: “How Are You?”    “7+2”   “5”     “d”

Variables

A variable is a data name that may be used to store a data value.

Constants remain unchanged during the execution of a program, a variable may take different values at different times during the execution of program.

  1. The variable name may consist of letters, digits, and the underscore character “_”, subject to the following conditions:
  2. The variable name can contain letters, digits and underscores
  3. The variable name must begin with a letter or underscore.
  4. Uppercase and lowercase are significant. The variable Sum is not the same as sum or SUM.
  5. The variable name should not be a keyword like int, float etc.
  6. Names cannot contain whitespaces or special characters like !, #, %, etc.

Data Types

C supports four classes of data types:

  1. Primary or fundamental data types
  2. User-defined data types
  3. Derived data types
  4. Empty data set

 

Desclaration of Variable: After designing suitable variable names, we must declare them to the compiler. Declaration does two things. 

i) It tells the compiler what the variable name is.

ii) It specifies what type of data the variable will hold.

The declaration of variables must be done before they are used in the program.

Primary Type

A variable can be used to store a value of any data type.

Syntax: data-type variable name;

Examples: int count;

                   int number, total;

                   double ration;

int and double are the keywords to represent integer type and real type data values respectively.

Data Types and Their Keywords are as follows:

Data Types                                              Keywords

Character                                                 char

Unsigned character                                 unsigned char

Signed character                                      signed char

Signed integer                                          signed int or int

Signed short integer                                 signed short int or short int or short

signed long integer                                    signed long int or long int or long

Unsigned integer                                       unsigned int or unsigned

Unsigned long integer                                unsigned long int or unsigned long

Floating point                                             float

Double precision floating point                  double

Extended double precision floating point   long double

User-Defined Type

The user-defined data type identifier can later be used to declare variables.

Syntax: typedef type indentifier;

Where type refers to an existing data type and “identifier” refers to the new name given to the data type.

Example: typedef int students;

                typedef float cars;

Here students symbolizes int and cars symbolizes float.

They can be used to declare variables as below:

students student1, student2;

cars name;

The main advantage of typedef is that we can create meaningful data type names for increasing the readability of the program.

Another user-defined data type is enumerated data type is defined as follows:

Syntax: enum identifier1 { value1, value2….valuen };

Example: enum company { tata, mahindra };

The compiler automatically assigns integer digits begining with 0 to all the enumeration constants.

Derived Data Types

The data types derived from the primary or fundamental data types are called Derived Data Types.

There are main three derived data types:

  1. Function
  2. Array
  3. Pointer
  4. Structure
  5. Union

Empty Data Set

A data type that has no values is know as empty data set.

void keyword used to represent empty data set.


Share this content on