Followers


Basic forms of the language C

Posted by Hari Sobri

Basic forms of the language C


The general form of the C programming language is as follows:

# include Files
# define var constants
function declaration
main ()
(
global variable declarations
:

:
)
function name (arg1, arg2, ....)
(
local variable declarations
:

:
)


# include
main ()
(
printf ( "Hello \ n");
)

Output
Hallo

Program Explanation

# include (stdio.h): contains information about standard library
main (): defines the function main (), main function there is no argument
(: Start of function body
printf ( "Hello \ n"): function main () calls printf library function that prints a number of characters in the mark "...."
): The end of the body functions



Example 2

# include
main ()

(
int num;
num = 1;

printf ( "I am a student");
printf ( "\tin STMIK Bidakara Jakarta \ n");
printf ( "I am in the st year% d \ n", num);

getchar ();
)
Output




Program Explanation
# include
- Include other files of a file stdio.h
- Contains information about input and output
- This line is not a statement in C
- This line is not always necessary

main ()
- A function name, the parentheses include information that is the argument
- In this case the function main () does not have an argument
- Must exist in the program, because of this function will start the program execution, without the function main () program will never implemented.
(
- Marks the beginning of the function
)
- Signal to end the definition of functions
; (Semicolon)
- To end each command
- Between the statements / commands to one another can only be separated by a semicolon (;) instead of separate lines or spaces or other characters

int num;
- A declaration statement that defines a variable named num as integer type
declaration statement is very important, because it declared 2 things:
1. in the function will have a variable named num
2. num variable has type integer
- In C, all variables must be declared

num = 1;
- An assignment statement that is giving the price of 1 at variable num
- Assignment statement is the most basic operations

printf ( "I am a student");
- A print statement to print the phrase in quotation marks

printf ( "\ tin STMIK Bidakara Jakarta \ n");
- \ N represents a single character, instruct the computer to initiate a new line
- \ N is one of the escape sequnce
- \ T tabulation (given the distance between words)

printf ( "I am in the st year% d \ n", num);
- Print a sentence in quotation marks by placing a variable price num (ie 1) at position% d
- The price of num "to substitute the symbols% d is:
1. placed at position% d
2. display the digits

The sentence in parentheses is the information transmitted by the function main (), to the function printf (). This information is called the argument. So on the first line "I am a student" is an argument. The function printf () takes the contents of the quotes and displays them on the screen.

Klik tombol like diatas... Jika anda menyukai artikel ini.
Terima Kasih telah mengunjungi Blog ini,
Jangan lupa untuk memberikan komentar, kritik maupun saran pada form dibawah post ini...

Share / Bagikan Artikel ini ke teman Anda :

{ 0 comments ... Tambahkan Komentar Anda }

Post a Comment

BERIKAN KOMENTAR DI SINI !!