Structure of program
/* This program prints Hello World on screen */
-----------------------------
#include
Void main()
{
printf(''Hello World
'');
}
-----------------------------
1 . /* This program ... */
The symbols/* and*/ used for comment. This Comments are ignored by the compiler, and are used to provide useful information about program to humans who use it.
2. #include
This is a preprocessor command which tells compiler to include stdio.h file.
3. main()
C programs consist of one or more functions. There must be one and only one function called main. The brackets following the word main indicate that it is a function and not a variable.
4. { }
braces surround the body of the function, which may have one or more instructions/statements.
5. printf()
it is a library function that is used to print data on the user screen.
6. ''Hello World
'' is a string that will be displayed on user screen
is the newline character.
; a semicolon ends a statement.
7. return 0; return the value zero to the Operating system.
C is case sensitive language, so the names of the functions must be typed in lower case as above.
we can use white spaces, tabs & new line characters to make our code easy to read.
Example of Structure in C
#include/* Created a structure here. The name of the structure is * StudentData. */ struct StudentData{ char *stu_name; int stu_id; int stu_age; }; int main() { /* student is the variable of structure StudentData*/ struct StudentData student; /*Assigning the values of each struct member here*/ student.stu_name = "Steve"; student.stu_id = 1234; student.stu_age = 30; /* Displaying the values of struct members */ printf("Student Name is: %s", student.stu_name); printf(" Student Id is: %d", student.stu_id); printf(" Student Age is: %d", student.stu_age); return 0; }
Output:
Student Name is: Steve Student Id is: 1234 Student Age is: 30


0 Comments