C Programming Language is one of the oldest Programming Language. C was developed by Dennis Ritchie in 1972, USA. It is used to program a wide variety of system, major parts of WINDOWS, LINUX and other operating systems are written in C. It also helps us to write driver programs for devices like Tablets, printers etc. Embedded systems are programmed by using C language, where programs need to run faster in limited memory (microwave, cameras etc.). C helps in development of games an area where latency is very important i.e. computer has to react quickly on user input.
We have seen the usage of C programming language and the importance of it still if u want to know that why you should prefer Coding language read our blog: Coding Language : A Strange Paradise of future!
In the very beginning we need to understand about VARIABLES, CONSTANTS & KEYWORD that are used in C.
VARIABLES
variables are data-containers used to hold one or more values. Instead of repeating these values in multiple places in your code, variables hold the results of a calculation, database call, results of a database query, or other value. Like in a kitchen, we have containers storing rice, sugar, salt etc. similar to that variables in C stores values of data. However, values of variables can be changed at any point of time.
For Example:
a=3; // a is assigned as 3
b=4.7; // b is assigned as 4.7
c= 'A' ; // c is assigned as 'A'
(We will learn about assignment operators in the upcoming chapters)
There are some rules for naming variables in C.
1. First character must be an alphabet or an underscore ( _ ).
2. No commas or blanks are allowed in names of variables.
3. No special symbol are allowed other than an underscore ( _ ).
4. Variable names are case sensitive.
Case sensitive : Differentiating between capital and lower case letters, it is treated differently depending on whether it is in capital or lower case text.
In order to enhance readability of our programs, we must create a meaningful variable names in our programs.
CONSTANTS
An entity whose value doesn't change is called as a constant. A variable is an entity whose value can be changed.
There are types of Constants.
Primarily, there are three types of constants.
1. Integer Constant ➝ 1, 6, -7, 9 etc.
2. Real Constant ➝ 33.2, 7.777, -8.9 etc.
3. Character Constant ➝ 'a', '$', '@' etc. (must be enclosed within single inverted commas)
KEYWORDS
These are reserved words, whose meaning is already known to the compiler.
There are 32 keywords available in C.
auto double int struct
break long else switch
case return enum typedef
char register extern union
const short float unsigned
continue signed for void
default sizeof goto volatile
do static if while
As we have seen variables, constants and keyword, now we will preceed to BASIC STRUCTURE OF A C PROGRAM.
But before that here's our first C program.
There are some rules which are applicable to all the C programs.
1. Every program's execution starts from main() function.
2. All the statements are terminated with semicolon (;).
3. Instructions are Case-sensitive.
4. Instructions are executed in the same order in which they are written.
COMMENTS
Comments are used to clarify something about us to add notes to our program.
There are two types of comments in C.
1. Single line comment:-
// This is a comment
2. Multi-line comment:-
/*
This is an example
of multi-line comment
*/
Comments in a C program are not executed and are ignored.
COMPILATION AND EXECUTION
A Compiler is a computer program which converts a C program into machine language so that it can be easily understood by the computer.
A C Program is written in plain text. This plain text is combination of instructions in a particular sequence. The compiler performs some basic checks and finally converts the Program into machine language so that it could be executed.
LIBRARY FUNCTIONS
C language has lots of valuable library function which is used to carry out certain tasks for instance printf function is used to print values on the screen.
printf ("This is %d", i);
%d for integers
%f for real values
%c for characters
we haven't seen the type of variable yet but now we will see what are its type.
1. Integer variable ➝ int a = 3 ;
2. Real variable ➝ float a = 7.7;
3. Character variables ➝ char a = 'B';
( \n = this is used for new line )
RECEIVING INPUTS FROM THE USER
In order to take input from the user and assign it to a variable, we use scanf function.
Syntax for using scanf:-
scanf ("%d", &i); // "&" is very important.
"&" signifies "address of" operator and it means that the supplied value should be copied to address which is indicated by i.
Q1. write a C program to calculate area of a rectangle, Using inputs supplied by the user.
ANSWER:
Q2. Calculate the area of a circle and modify same program to calculate the volume of a cylinder given its radius and height.
ANSWER:
Q3. Write a program to convert Celsius ( centigrade degree temperature to Fahrenheit ).
ANSWER:
Q4. Write a program to calculate simple interest for a set of values representing principal, no of years and rate of interest.
ANSWER:
THIS IS WHERE WE COMPLETE OUR CHAPTER 01. FOR ANY QUERIES DO ASK IN THE COMMENT SECTION OR EMAIL ME AT aniket0130ak@gmail.com
0 Comments