Вы находитесь на странице: 1из 15

By Disha Verma

A C program basically consists of the following parts:

Preprocessor Commands Functions Variables Statements & Expressions Comments

First Program

various parts of the above program:


The first line of the program #include <stdio.h> is a preprocessor command which tells a C compiler to include stdio.h file before going to actual compilation. The next line int main() is the main function where program execution begins. The next line /*...*/ will be ignored by the compiler and it has been put to add additional comments in the program. So such lines are called comments in the program. The next line printf(...) is another function available in C which causes the message "Hello, World!" to be displayed on the screen. The next line return 0; terminates main()function and returns the value 0.

Variables in C
Variables in C : Variable is used to store the values temporarily during the execution (runtime) of the program. Variables are allocated Memory Space (in RAM) depending on the data type. First we have to declare the needed variables in our program before actually using it. Declaring the variables doesnt guarantee that space is allocated in the Main Memory (RAM). The space is allocated during the execution (runtime) of the program.

Rules for declaring Variables in C :


The 1st letter should be alphabet. Variables can be combination of alphabets and digits. Underscore ( _ ) is the only special character allowed. Variables can be written in both Uppercase and Lowercase orcombination of both. Variables are Case Sensitive. No Spaces allowed between Characters. Variable name should not make use to the C Reserved Keywords. Variable name should not start with a number. Eg : - a, number, s5, book_no etc.

Primitive data types int, float, double, char Aggregate data types Arrays come under this category Arrays can contain collection of int or float or char or double data User defined data types Structures and enum fall under this category

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 three data types above have the following modifiers. short long signed unsigned The modifiers define the amount of storage allocated to the variable. ANSI has the following rules: short int <= int <= long int float <= double <= long double

Вам также может понравиться