Sei sulla pagina 1di 10

Day 2

Hello World in C
#include <stdio.h> void main() { clrscr();

Program mostly a collection of functions

main function is the entry point of the program

void qualifier indicates function does not return anything

printf(\n\n\t Hello, world); getch();


I/O performed by a library function

Comments
Instructions, documentation, description about the program that do not execute Single line comments Multiline comments : : // /*. ..*/

Preprocessor Directives
The #include is a "preprocessor" directive that tells the compiler to put code from the header file called stdio.h into our program before actually creating the executable.

#include<stdio.h> it tells the compiler to include the <stdio.h> header file for compilation Header files contain prototype and definitions of the functions and instructions used in a program

Some common header files are stdio.h, conio.h, stdlib.h, math.h, etc

All statements should be entered in small case letters C has no specific rules for the position at which a statement to be written

Every C statement must end with a ; thus ; acts as a statement terminator.

Main () Function
It is an entry point of the program

Printf() function
The printf() function is the standard way of C to display output on the screen.

getch() function
This is another function call it reads in a single character from the keyboard This command keeps the output window from closing

Rules
Each instruction in a C program is written as a separate statement. The statements in a program must appear in the same order in which we wish them to be executed. Blank spaces may be inserted between two words to improve the readability of the statement, (no blank spaces are allowed within a variable, constant or keyword)

Potrebbero piacerti anche