Page Nav

HIDE

Grid

GRID_STYLE

Classic Header

{fbt_classic_header}

Search This Blog

Notes:

latest

05_Data Types_C progarmming



Character Set

Alphabets: a,b,c........z or A,B,C,….....Z or _  (underscore)

Digits:   0,1,2,3,4,….9

Special Symbol: !, $, &, @, #, ^, *.. etc

White spaces:  blank space, horizontal tab, new line.....



Comment


A comment is a text in the program which wont be compiled or executed.


Single line comment: It is written by using ; //....comment.....


//This is the comment which is no executed.


Multi-line comment: It is written by using '/*…....comment........*/'



C Tokens

The basic and smallest element used to develop the program and recognized by the c compiler is called c tokens.

There are five types of tokens which are:

  1. Keywords: float, while, if....etc

  2. Identifier: num, sum....etc

  3. Constants: 1,2,3...etc

  4. String Constants: "ABC", "Global IT"…..etc

  5. Operators: +, -, *, /....etc


Keywords


Keywords is a reserved word that has standard and predefined meaning in C. It has already defined in C programming language.

The keywords cannot be used as variable names/ identifier because if we try to do so, then we are trying to assign a new meaning to the keyword, which is not allowed by the compiler.

There are 32 keywords in C:

  

auto

const

double

float

int

short

struct

unsigned

break

continue

else

for

long

signed

switch

void

case

default

enum

goto

register

sizeof

typedef

volatile

char

do

extern

if

return

static

union

while




Identifier


The identifier is the name given to various program

elements such as variable, function, label and an

other user-defined item.

There are 53 alphabetic character: 52 letters and

one is _ (underscore)

Rules:

Must consist of only letters, digits, or underscore

First letter must be alphabet or _

Only first 31 characters are significant

Keyword cannot be used as identifier

Must not contains white space.


Data Types


The data types is an instruction that is used to

declare the category or type of the variable being

used in the program. Any variable used in the program

must be declared before using

it.

Data types can be classified as:

Primary Data Types:

  • int
  • float
  • char
  • void

Derived Data Types:

  • function
  • array
  • pointer
User-defined Data types:

  • structure
  • union


Primary Data Types


Primary Data Types, their size and range

 

Type

Size (bytes)

Range

Int or signed int

2

-32,768 to 32,767

Unsigned int

2

0 to 65535

Short  int or signed short int

1

-128 to 127

Unsigned short int

1

0 to 255

Long int or signed long int

4

-2,147,483,648 to 2,147,483,647

Unsigned long int

4

0 to 4,294,967,295

float

4

3.4E-38 to 3.4E+38

double

8

1.7E-308 to 1.7E+308

Long double

10

3.4E-4932 to 1.1E+4932

Char or signed char

1

-128 to 127

Unsigned char

1

0 to 255


Constant and Variable


A value that does not change during the execution

of the programs is called constants.

Variable is a symbolic name which is used to store

different types of the data in the computer memory

and may change during the program execution.


Variable Declaration

Syntax:

int num;

Variable Initilization

Syntax:

int num=10;


Local Variable and Global Variable

Local Variable

Global Variable

It is declared inside a function

It is declared outside the function

If it is not initilized, a garbage value is stored

If it is not initilized zero is stored as default.

Data of the local variable can be accessed by only one function.

Data of the global variable can be accessed by multiple functions.

It is stored on the stack unless specified.

It is stored on a fixed location decided by the compiler.

e.g.

#include<stdio.h>

int main()

{

int num;


return 0;

}

e.g.

#include<stdio.h>

int num;

int main()

{



return 0;

}



Download the PDF file


-----------------------------------------------------------------------------------------------------------------------------
The End
-----------------------------------------------------------------------------------------------------------------------------

No comments

If you have any doubts, Please let me know,

Click here to show more posts