Freshers Aptitude technical questions
Freshers Job Alert
Bookmark and Share

C Programming Tutorial

Learn C programming in an easy way.This C programming tutorial is completly free for your use.

How you can help us back is let us know about more tutorials and send us the tutorial with your small photo and name.We will publish tutorial in your name.

 

<< Tutorial Home

A SIMPLE C PROGRAM
The following program is written in the C programming language.

#include <stdio.h> main() { printf("Programming in C is easy.\n"); } Sample Program Output Programming in C is easy. _

A NOTE ABOUT C PROGRAMS
In C, lowercase and uppercase characters are very important! All commands in C must be lowercase. The C programs starting point is identified by the word

main()

This informs the computer as to where the program actually starts. The brackets that follow the keyword main indicate that there are no arguments supplied to this program ( this will be examined later on ).

The two braces, { and }, signify the begin and end segments of the program. The purpose of the statment

# include <stdio.h>

is to allow the use of the printf statement to provide program output. Text to be displayed by printf() must be enclosed in double quotes. The program has only one statement

printf("Programming in C is easy.\n");

printf() is actually a function (procedure) in C that is used for printing variables 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 modifier's , and for the present the \ followed by the n character represents a newline character. Thus the program prints

Programming in C is easy.

and the cursor is set to the beginning of the next line. As we shall see later on, what follows the \ character will determine what is printed, ie, a tab, clear screen, clear line etc. Another important thing to remember is that all C statements are terminated by a semi-colon ;

 

Summary of major points so far

  • program execution begins at main()
  • keywords are written in lower-case
  • statements are terminated with a semi-colon
  • text strings are enclosed in double quotes
  • C is case sensitive, use lower-case and try not to capitalise variable names
  • \n means position the cursor on the beginning of the next line
  • printf() can be used to display text to the screen
  • the curly braces {} define the beginning and end of a program block

CLASS EXERCISE C1
What will the following program output?

#include <stdio.h> main() {

printf("Programming in C is easy.\n");

printf("And so is Pascal.\n"); }

And this program?

#include <stdio.h> main() {

printf("The black dog was big. ");

printf("The cow jumped over the moon.\n"); }

Another thing about programming in C is that it is not necessary to repeatedly call the printf routine, so try and work out what the following program displays,

#include <stdio.h> main() {

printf("Hello...\n..oh my\n...when do i stop?\n");

}

 

<< Tutorial Home