Introduction
As I believe that "C" language is the mother of all programming languages, if one knows "C" then it will be easier to understand any other programming language such as C++, C#, JAVA and many other. But right now I shell concentrate with "C" only.
C is a procedural programming language, code is generally reside either in library function or the functions defined by us (developer).
Library functions are ready to use such as (printf(), scanf(), etc.,) where as user defined functions have to be developed by us.
Lets directly move to the structure of "C" program and few simple programs.
General program structure
// main function declaration
// declaration of variables
// body of main function
Example : 1
void main()
{
printf ("Hello World !!!");
}
output:
Hello World!!!
Note:
press (ALT+F5) to see the output
Lets understand the above code:
- in above example main() is user defined function with return type void means its returns nothing to the operating system (don't bother about return type, we shell discuss it later).
- main() is the starting point of our code, compiler starts program execution from main() function only.
- printf() is library function that displays text message and the value of variables to the console screen, right now its displays the "Hello World !!!" to the console screen
output:
Hello World!!!Hello World!!!
Hello World!!!Hello World!!!
because, the output of previously ran program remain on the screen which comined with the output of current output, so its like above.
To clear the console screen before running our program, we muse have to use function called clrscr(), generally its the first statement in program after the declaration and before any statement.
lets Rewrite the above program with clrscr() function to clear the screen
Example : 2
void main()
{
clrscr(); // clear the console screen
printf ("Hello World !!!");
}
output:
Hello World!!!
Each time to see the output one must have to press (ALT+F5), and make it simpler one may use another library function called getch(), this function reads a character from keyboard.
So, one can use it at the end of program, so the console will wait for you enter a character, meanwhile one can check the output given by your code.
Example : 3
void main()
{
clrscr();
printf ("Hello World !!!");
getch(); // read a char. from user via keyboard
}
output:
Hello World!!!
Exercise:
1. print the following output using printf()
* * * * *
* *
* *
* *
* * * * *
2. print your personal information using printf() like following
surname : ______
name : ______
father : ______
etc.
Data is about information generally given by end user and type is about what kind of data given by user.
For example : Name of a person or an age of person, name generally contains characters where as the value of age is always going to be a number, which is nothing but classification of data given by user in terms of values entered.
Broad categories of data types
character (char)
integer (int)
To clear the console screen before running our program, we muse have to use function called clrscr(), generally its the first statement in program after the declaration and before any statement.
lets Rewrite the above program with clrscr() function to clear the screen
Example : 2
void main()
{
clrscr(); // clear the console screen
printf ("Hello World !!!");
}
output:
Hello World!!!
Each time to see the output one must have to press (ALT+F5), and make it simpler one may use another library function called getch(), this function reads a character from keyboard.
So, one can use it at the end of program, so the console will wait for you enter a character, meanwhile one can check the output given by your code.
Example : 3
void main()
{
clrscr();
printf ("Hello World !!!");
getch(); // read a char. from user via keyboard
}
output:
Hello World!!!
Exercise:
1. print the following output using printf()
* * * * *
* *
* *
* *
* * * * *
2. print your personal information using printf() like following
surname : ______
name : ______
father : ______
etc.
Data Types
It is combination of two words data and types respectively.Data is about information generally given by end user and type is about what kind of data given by user.
For example : Name of a person or an age of person, name generally contains characters where as the value of age is always going to be a number, which is nothing but classification of data given by user in terms of values entered.
Broad categories of data types
character (char)
integer (int)
No comments:
Post a Comment