Powered by Blogger.

Text Widget

Featured

Recent Post

Follow

Popular Posts

Featured

Pages

Subscribe

Kamu Pasti Tertarik

Most Popular
Videos

MoreBaru diupdate

Gallery

story

Thursday, 7 January 2016

structure of C

To have a proper start we must know the structure of the program with the usage of each line. In this post, let me explain you people about it.


STRUCTURE:

header files
main()
{
//code
}
example:
#include
#include
void main()
{
//code
printf();
scanf();
}

main():

The main() function is where the program starts its execution. The program's execution is completed after the control encounters the last braces '}' in the main() function.

void: The datatype of the main() function can be any datatype. It is mostly void. void is a datatype which indicates that no value is available. 

return: The return statement returns the execution of the program to the calling function. It can also return a value to the calling function.

exit: There is an other function called as exit similar to that of return. The major difference is that the return function exits from the function whereas the exit function returns from the program.

printf():

This is a formatted output function. printf is used to print a line in the output screen. 
syntax:
printf("text to be printed");

BACKSLASH CONSTANTS:

These constants are used in printf statements. Some of the commonly used backslash constants are - 
\n - new line
\t - horizontal tab

scanf():

This is a formatted input function. scanf is used to get an input from the user.
syntax:
scanf("format_specifiers",&variable);

Format specifiers:
d: integer values 
f: floating point values
s: string values
c: character values

PREPROCESSOR:

All the preprocessor directives begin with the pound (hash #) symbol. They are invoked by the compiler to process some files before compilation.

#include: This is used to include some system files - header files  (#include <"filename">) or user files(#include "filename") into the program.

#define: This preprocessor is used to define a constant value.
syntax: #define variable value

eg: 
#define height 100
void main()
{
int weight;
printf(“Enter the value of weight \n);
scanf("%d",&weight);
printf(“value of height and weight : %d %d \n”, height, weight );
}

Header files: Header files are those with an extension '.h'
Most commonly used header files are as follows:
stdio.h: to include standard input output functions like printf,scanf,etc.
conio.h: to include console input/output functions like getch,clrscr,etc.
stdlib.h: to include general purpose standard library functions like malloc,freealloc,etc.
math.h: to include various mathematical functions like ceil,floor,pow,sqrt,etc.

Tags: preprocessor, structure of c program, header files, formatted input and output, main().



Copy Article URL:

No comments:

Post a Comment

Template By Way2Themes | Some Rights Reserved.