HTML/JavaScript

Notes On Tokens, Variable and Datatypes In C

 

Today, We’ll discuss about basic syntax of C language:


First of all, let’s see some of the basic terms in C language -:


 Tokens: These are the smallest elements of a program, which are meaningful to the compiler.


Types of Tokens:-

  • Keywords, Identifiers, Constants, Operators etc.


Keyword: These are reserved (pre-defined) words in the C programming language.

  • There are 32 general-purpose keywords.
  •                         


Identifiers: Each program element in C is known as the Identifier. They are used for the naming of variables, functions, arrays, etc.

  • These are user-defined names which consist of alphabets, numbers, underscore (_).


C Program is made up of Keywords, Identifiers, Constants, String Literal & Symbol.


Variable -:

·      A variable is a name or an identifier which is given to any storage area or memory location.

Actually, Variable doesn’t hold a value but it’s the name given to any memory address in RAM. It means the variable is the way to access that memory address of Ram so that we can store or manipulate data in that memory address or memory block.

·      It’s a name of memory location.


Declaring a variable -:

·      Variables are declared by writing :

Typeofvariable name;

·      For E.g. : char abc; , int num1; , float add; etc.

·      Initializing means entering data in that variable i.e. storing some value in that variable.

·      Variable can be initialized and declared as :

Typeofvariable name = value;

·      For E.g. : int num1 = 52; , char demo = ‘A’; ,

float add=56.28; etc.


Rules for defining a variable in C:-

·      Variable name can contain alphabets, digits, and underscore (_).

For E.g. : int demo_xyz;

·     Variable name can start with an alphabet and underscore only.

For E.g. : int _demo; , int de_mo;

·      It can’t start with a digit.

·      No whitespace and reserved keywords are allowed to use as a variable name.


·      Valid Variable Names :

int demo; , float demo123; , char _demo123; etc.


·      Invalid Variable Names :

$demo; , int 123demo; , char float;


Data Types -:

·      Data type is the type of data that the variable holds.

·      These are used for assigning a type to a variable.


  • The words which are both data type and keyword in C Language are known as Primitive Data Type.

Such as int, char, float, double, and void.

·     Basic Data Type: These are the fundamental data type of C Language.

E.g. : int, char, float, double.

·      Derived Data Type: These are the data types that are made with the help of Basic Data Types.

E.g. : array, pointer, structure, union.

·      Enumeration Data Type : enum.

·      Void Data Type: It is the data type that denotes the value empty i.e. Void data type means “no data type”.


·      Data Type Size varies from architecture to architecture. It means a 32bit architecture system can have some other size for any specific data type then a 64bit architecture system.

Here, is the list of the size of all data types:

                                

Post a Comment

0 Comments