DATA TYPES AND OPERATORS IN C

       CHAPTER 2

DATA TYPES , USER I/O OPERATORS 


DATA TYPES

Thedatatypespecifythetypeofdatathatavariablecanstore.

• A datatype is used to:
• Identify the type of a variable when the variable is declared 

• Identify the type of the return value of a function
• Identify the type of a parameter expected by a function


• ANSI C supports three classes of data types.

1. Primary or Fundamental data types.

 2. User-defined data types.

3. Derived data types.


Primary Data Types

C provides 5 primary or fundamental data types

  • Character- char 
  • integer- int
  • floating point -float double
  • void.

Extended data type

We can also use the short, long, signed and unsigned keywords to extend the primary data typesSo, they are called extended data types


Primary Data Types in C


Datatypes-in-C- Logicmojo

Integer Types

 Size and Range Of Data types on 16 bit machine

C Tutorials - data types in C Programming Language


Floating Point Types

C Tutorials - data types in C Programming Language


VOID

The void data type is generally used with function to denote that function is return nothing.


User-defined type declaration

• C allows user to define an identifier that would represent an existing data type. • Thegeneralformistypedeftypeidentifier;
Eg:

typedef int units; typedef float marks;

• Another user defined data types is enumerated data type which can be used to declare variables that can have one of the values enclosed within the braces.

• enumidentifier{value1,value2,......valuen};

Derived data type

• C allows a different types of derived data structure • Different types of datatypes are
• array
• Functions

• Pointer
• Structure

DECLARATION OF VARIABLES

• Declarationsdoestwothings:
It tells the compiler what the variable name is
It specifies what type of data the variable will hold

Primary Type Declaration

 • The syntax is
• Data-typev1,v2.....vn; 

Eg:

int count;
double ratio, total;

User-defined type declaration

  • C allows user to define an identifier that would represent an existing int data type.

  • The general form is typedef type identifier;

    Eg:

    typedef int units; typedef float marks;

    • Another user defined data types is enumerated data type which can be used to declare variables that can have one of the values enclosed within the braces.

    • enum identifier {value1,value2,......valuen};

User-defined type declaration

Declaring a variable as constant

Eg:

const int class_size=40;

• This tells the compiler that the value of the int variable class_size must not be modified by the program. Declaring a variable as volatile

By declaring a variable as volatile, its value may be changed at any time by some external source. Eg:

volatile int date;

USER I/O

C language has standard libraries that allow input and output in a program. The stdio.h or standard input output library in C that has methods for input and output.

scanf() function

The scanf() method, in C, reads the value from the console as per the type specified.

Syntax:

scanf(“%X”, &variableOfXType);

 where %X is the format specifier in C.







Comments