'C' Basics part-1
Why 'C' language is so popular/powerful?
C is a Middle Level Language;it has the features of both low-level languages and high-level languages. i.e., software development is relatively faster than assembly language (low level) and program execution is relatively faster than other high-level programming languages.
Communication with the Hardware is easy which was earlier possible only with assembly languages.
It is suited for a variety of programming domains.
° System programming
° General application programming
° Embedded systems programming
° Game Programming
° Network programming
Most of the software in the world were developed using C/C++. The world's software giants, Microsoft, Borland develop most of their software using C & C++.
In fact anything and every thing can be done on computer, can be done using 'C' , provided we are good at it and the Particular programming domain.
Why was ''C'' invented
C was invented to create a portable Operating System and the first portable Operating system was UNIX
How to write a program?
To write a program we need an editor software. To write a ''C'' Program we have a special editor called ''TurboC editor'' (Integrated Development Environment), which is an integration of several tools.
¬ Editor
¬ Preprocessor
¬ Debugger
¬ Compiler
¬ Linker
¬ Standard Object Library
¬ Header Files
¬ Help Document
program 1.1
i.)void main()
{
printf(''Welcome to C'');
}
Output
Welcome to C
After typing the program follow these steps Step 1: Save your program using the File menu of your Turbo C IDE.
Step 2:Compile -> Alt + F9
Step 3:Link -> F9
Step 4:Execute -> Ctrl + F9
Step 5:To view the result -> Alt +F5
Explanation
a) The same program could have been written in two more ways.
ii.) main()
{
printf(''Welcome to C'');
}
iii.) int main()
{
printf(''Welcome to C'');
return 0;
}
Earlier we learned that a C program is nothing but a collection of functions. There can be any number of functions in a program, main() is the compulsory function in a C program because it is both the entry point and exit point of a program.
Parentheses are used to indicate a function.
A function contains a set of instructions enclosed with a pair of braces ({ and}).
Printf() is a library function which is used to print a message (with in double quotes) on the screen.
void : it indicates that the main() function doesn't return any value.
Every instruction must be terminated with a semicolon.
Basic I/O operations
How to store data in the memory?
Any program is meant for processing some kind of input data & get desired results. The microprocessor or device processes data. The microprocessor can process data only if the data is available in RAM (primary memory). To store any data in RAM we have to reserve required amount of memory.
Reading a number from the keyboard, storing it in the memory & then printing it on the screen
Program 1.2
void main()
{
int n;
printf(''Enter a number:'');
scanf(''%d'', &n);
printf(''%d'', n);
}
output
Enter a number: 786
786
Explanation
a) int n;
this statement tells the compiler to reserve sufficient amount of memory to store an integer (number) value(2 bytes for an integer) and give a name 'n' to that memory location.
786 ------>Constant value
n -------->Variable Name (location name)
65422--------->Location ( address)
b) scanf() is a library function which is used to accept a data item from the keyboard & store it in the specified memory location.
c) %d called as format specifier. It tells the compiler that we are going to read a decimal number.
d) & is called as address of operator
e) &n tells the compiler to store the accepted value in the location whose name is n.
f) note that & is required only in the scanf() function, but not in the printf() function.
1.3 Sum of two integers
void main()
{
int a, b, c;
printf(''Enter two numbers:'');
scanf(''%d%d'', &a, &b);
c=a+b;
printf(''Sum is %d'', c);
}
Output
Enter two numbers : 45
72
Sum is 117
Explanation
a) '+' and '=' are operators in C, whereas 'a', ' b', 'c' are operands. Operand is an entity, which can be a variable/constant/expression. Note that the left side of '=' operator can be only a variable.
b) The value of a+b is assigned to the variable C
Why 'C' language is so popular/powerful?
C is a Middle Level Language;it has the features of both low-level languages and high-level languages. i.e., software development is relatively faster than assembly language (low level) and program execution is relatively faster than other high-level programming languages.
Communication with the Hardware is easy which was earlier possible only with assembly languages.
It is suited for a variety of programming domains.
° System programming
° General application programming
° Embedded systems programming
° Game Programming
° Network programming
Most of the software in the world were developed using C/C++. The world's software giants, Microsoft, Borland develop most of their software using C & C++.
In fact anything and every thing can be done on computer, can be done using 'C' , provided we are good at it and the Particular programming domain.
Why was ''C'' invented
C was invented to create a portable Operating System and the first portable Operating system was UNIX
How to write a program?
To write a program we need an editor software. To write a ''C'' Program we have a special editor called ''TurboC editor'' (Integrated Development Environment), which is an integration of several tools.
¬ Editor
¬ Preprocessor
¬ Debugger
¬ Compiler
¬ Linker
¬ Standard Object Library
¬ Header Files
¬ Help Document
program 1.1
i.)void main()
{
printf(''Welcome to C'');
}
Output
Welcome to C
After typing the program follow these steps Step 1: Save your program using the File menu of your Turbo C IDE.
Step 2:Compile -> Alt + F9
Step 3:Link -> F9
Step 4:Execute -> Ctrl + F9
Step 5:To view the result -> Alt +F5
Explanation
a) The same program could have been written in two more ways.
ii.) main()
{
printf(''Welcome to C'');
}
iii.) int main()
{
printf(''Welcome to C'');
return 0;
}
Earlier we learned that a C program is nothing but a collection of functions. There can be any number of functions in a program, main() is the compulsory function in a C program because it is both the entry point and exit point of a program.
Parentheses are used to indicate a function.
A function contains a set of instructions enclosed with a pair of braces ({ and}).
Printf() is a library function which is used to print a message (with in double quotes) on the screen.
void : it indicates that the main() function doesn't return any value.
Every instruction must be terminated with a semicolon.
Basic I/O operations
How to store data in the memory?
Any program is meant for processing some kind of input data & get desired results. The microprocessor or device processes data. The microprocessor can process data only if the data is available in RAM (primary memory). To store any data in RAM we have to reserve required amount of memory.
Reading a number from the keyboard, storing it in the memory & then printing it on the screen
Program 1.2
void main()
{
int n;
printf(''Enter a number:'');
scanf(''%d'', &n);
printf(''%d'', n);
}
output
Enter a number: 786
786
Explanation
a) int n;
this statement tells the compiler to reserve sufficient amount of memory to store an integer (number) value(2 bytes for an integer) and give a name 'n' to that memory location.
786 ------>Constant value
n -------->Variable Name (location name)
65422--------->Location ( address)
b) scanf() is a library function which is used to accept a data item from the keyboard & store it in the specified memory location.
c) %d called as format specifier. It tells the compiler that we are going to read a decimal number.
d) & is called as address of operator
e) &n tells the compiler to store the accepted value in the location whose name is n.
f) note that & is required only in the scanf() function, but not in the printf() function.
1.3 Sum of two integers
void main()
{
int a, b, c;
printf(''Enter two numbers:'');
scanf(''%d%d'', &a, &b);
c=a+b;
printf(''Sum is %d'', c);
}
Output
Enter two numbers : 45
72
Sum is 117
Explanation
a) '+' and '=' are operators in C, whereas 'a', ' b', 'c' are operands. Operand is an entity, which can be a variable/constant/expression. Note that the left side of '=' operator can be only a variable.
b) The value of a+b is assigned to the variable C
Comments
Post a Comment