techpreparation-homepage

Home  Interview Questions  Certifications  Aptitude Questions  Tutorials  Placement Papers  Search  Resume  Soft Skills  Video  Forum  Blog

  C Programming Tutorials
Basics of C:
Facts about C
Why to Use C
C Program File
C Compilers

Program Structure:
Simple C Program
C Program Compilation

Basic DataTypes:
DataTypes
Modifiers
Qualifiers
Arrays

Variable Types:
Local Variable
Global Variable

Storage Classes:
auto storage class
register storage class
static storage class
extern storage class

Using Constants:
Defining Constants
The enum Data Types

Operator Types:
Arithmetic Operators
Logical Operators
Bitwise Operators
Assignment Operators
Misc Operators

Control Statements:
Branching
Looping

Input and Output:
printf() function
scanf() function

Pointing to Data:
Pointers and Arrays
Pointer Arithmetic
Pointer Arithmetic with arrays

Functions:
Using functions
Declaration and Definition

Strings:
Reading and Writing Strings
String Manipulation Function

Structured DataTypes:
Structure
Pointer to Structure

Working with Files:
Files
Basic I/O

Bits:
Bits Manipulation
Bits Field

Pre-Processors:
Pre-Processors Examples
Parameterized Macros
Macro Caveats

Useful Concepts

Built-in Library Functions:
String Manipulation Function
Memory Management Function
Buffer Manipulation
Character Functions
Error Handling Functions

Soft Skills
Communication Skills
Leadership Skills
                              .........More

 

 

  

C Programming Tutorials


Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use. The definition of a variable will assign storage for the variable and define the type of data that will be held in the location.

The value of a variable can be changed any time.

C has the following basic built-in datatypes.

  • int

  • float

  • double

  • char

Please note that there is not a Boolean data type. C does not have the traditional view about logical comparison, but that's another story.

int - data type
int is used to define integer numbers.

 {
int Count;
Count = 5;
}

float - data type
float is used to define floating point numbers.

 {
float Miles;
Miles = 5.6;
}

double - data type
double is used to define BIG floating point numbers. It reserves twice the storage for the number. On PCs this is likely to be 8 bytes.

 {
double Atoms;
Atoms = 2500000;
}

char - data type
char defines characters.

 {
char Letter;
Letter = 'x';
}

Modifiers
The data types explained above have the following modifiers.

  • short

  • long

  • signed

  • unsigned

The modifiers define the amount of storage allocated to the variable. The amount of storage allocated is not cast in stone. ANSI has the following rules:

 short int <= int <= long int
float <= double <= long double

What this means is that a 'short int' should assign less than or the same amount of storage as an 'int' and the 'int' should be less or the same bytes than a 'long int'. What this means in the real world is:

 Type Bytes Range  
short int 2 -32,768 -> +32,767 (32kb)
unsigned short int 2 0 -> +65,535 (64Kb)
unsigned int 4 0 -> +4,294,967,295 ( 4Gb)
int 4 -2,147,483,648 -> +2,147,483,647 ( 2Gb)
long int 4 -2,147,483,648 -> +2,147,483,647 ( 2Gb)
signed char 1 -128 -> +127  
unsigned char 1 0 -> +255  
float 4    
double 8    
long double 12    

These figures only apply to today's generation of PCs. Mainframes and midrange machines could use different figures, but would still comply with the rule above.

You can find out how much storage is allocated to a data type by using the sizeof operator discussed in Operator Types Session.

Here is an example to check size of memory taken by various datatypes.

int
main()
{
printf("sizeof(char) == %d\n", sizeof(char));
printf("sizeof(short) == %d\n", sizeof(short));
printf("sizeof(int) == %d\n", sizeof(int));
printf("sizeof(long) == %d\n", sizeof(long));
printf("sizeof(float) == %d\n", sizeof(float));
printf("sizeof(double) == %d\n", sizeof(double));
printf("sizeof(long double) == %d\n", sizeof(long double));
printf("sizeof(long long) == %d\n", sizeof(long long));

return 0;
}

NEXT >> Qualifiers

Have a Question ? post your questions here. It will be answered as soon as possible.

Check C Aptitude Questions for more C Aptitude Interview Questions with Answers

Check C Interview Questions for more C Interview Questions with Answers