Sunday, 22 February 2015

Procedural Programming


Write your first C program



  1.  The C program starting point is identified by the word main(). 
  2.  This informs the computer as to where the program actually starts. The parentheses that follow the keyword main indicate that there are no arguments supplied to this program (this will be examined later on). 
  3. The two braces, { and }, signify the begin and end segments of the program. In general, braces are used throughout C to enclose a block of statements to be treated as a unit. 

N.B=COMMON ERROR: unbalanced number of open and close curly brackets! 

 


The purpose of the statement #include is to allow the use of the printf statement to provide program output. For each function built into the language, an associated header file must be included. Text to be displayed by printf() must be enclosed in double quotes. The program only has the one printf() statement. 



printf() is actually a function (procedure) in C that is used for printing variable’s values and text. Where text appears in double quotes "", it is printed without modification. There are some exceptions however. This has to do with the \ and % characters. These characters are modifiers, and in this code the \ followed by the n character represents a newline character.



Thus the program prints  Hello World !

 

And the cursor is set to the beginning of the next line. As we shall see later on,
the letter that follows the \ character will determine what special printing
action is taken (i.e., a tab, backspace, clear line, etc.)

/* My first program */ 


Comments can be inserted into C programs by bracketing text with the /* and
*/ delimiters. As will be discussed later, comments are useful for a variety of
reasons. Primarily they serve as internal documentation for program structure
and functionality.





 

No comments:

Post a Comment