TOPIC 4: Structure Of C Program
Structure of C program is defined by set of rules and regulations called protocol, to be followed by programmer while writing C program. All C programs are having sections which are mentioned below.
- We can give comments about the program, date of creation, author name etc in this section.
- NOTE:The characters or words which are given between “/*” and “*/”, won’t be considered by C compiler for compilation process.
- This process is known as commenting out and is basically used to increase the readibility of the program.
- Example:/* This is my first program */ .Here the text inside /* and */ will be ignored by the C compiler.
- The files that are required to execute a C program are called as Header files are included in this section.
- Variables are defined and values are set to these variables in these section.
4.Global Declaration Section
- In this section,Global variables are defined.The variable which is to be used throughout the program is defined in this section.
5.Function Prototype Declaration Section
- Function prototype gives a lot of information about a function like return type, parameter names used inside the function.
- Every C program begins from main function and this function contains two major sections called declaration section and executable section.
7.User Defined Function Section
- User can define their own functions in this section which performs particular task as per the user requirement.
TOPIC 5: Standard Input/Output in C Programming
- stdio.h is basically the name of the standard library definition file for all STanDard Input and Output functions.
- Your program will certainly want to send data to the screen and read things from the keyboard, and stdio.h is the name of the file in which the functions that we want to use are defined.
- The function we use is called printf. The actual code of printf will be tied in later by the linker.
- The ".h" portion of the filename is the extension of the language, which denotes an include file.
- Example: #include<stdio.h>
- In various other programming languages, the printing and reading functions are a part of the language.
- This is not the case of C programming language; in C they are defined as standard functions which are part of the language specification, but are not a part of the language itself.
- The standard input/output library contains a number of functions for formatted data transfer; the two we are commonly used are scanf (scan formatted) and printf (print formatted).
- Example: scanf("%d",&n);
- The printf function is the opposite of scanf.
- It takes values and text from within the program and sends it out onto the screen.
- Just like scanf, it is described in the system file stdio.h.
- The first parameter to a printf is the format string, which contains text, values and formatting instructions.
- Example: printf("Hello World");
- The int getchar function reads the next character from the screen and returns it as an integer.
- Only single character is read from the function at a time.
- We can use this method in the loop in case you want to read more than one characters from the screen.
- Example: Getc()
- The int putchar function puts the passed character on the screen and returns the same character.
- Only single character is put by the function at a time.
- We can use this method in the loop in case you want to display more than one character on the screen.