- C is a general-purpose programming language that follows the procedural approach of software development
- C language is the mother of all other programming languages and was developed by Dennis Ritchie in 1972. Ritchie developed it by improving B language (developed by Ken Thompson) as it was considered slow and have not to support features like byte addressability. The development of the C language was followed by the development of the Unix operating system, the first operating system written in a high-level language i.e. C language, and even the C compiler itself written in C language.
- In 1978, Ritchie and Kernighan published the first edition of the book -- “The C programming language” referred to as the K&R version of the C language. The second and improved version of the book was published by ANSI (American National Standard Institute) C standard in 1989. C grew into new and improved flavors over the years. The latest version of the C language is C18, extending no new features but simply certain technical corrections to anomalies in C11
- C is a high-level programming language that provides support to a low-level programming language as well.`i.e. C is a middle-level language.
- A high-level language is similar to the human language and is easy to
understand and write. High-level language focuses more on arithmetic
operations, program efficiency, and simplicity in coding. We use it in developing the program in an easy and understandable
way.
- A procedural language follows well-organized architecture by specifying all the steps that the computer must take to obtain the desired output. Programming languages like C, Fortran, BASIC, Pascal, and C++ follow procedural programming. It is a programming paradigm consisting of a set of a computational hierarchy of steps to execute a program.
STRUCTURE OF C PROGRAM :
The structure of the C program format is given below:
|
Serial number |
Sections of program |
Example |
|
1. |
Comment section both single-line comment and multiline comment both
explain the objective or logic of the program along with different parts or
line of program (OPTIONAL) |
/*--------------------- NUMBER REVERSE PROGRAM-----------*/ OR // VARIABLE DECLARATION |
|
2. |
Header file section All header files which are actually the collection of
the different functions called inbuild functions included here (COMPULSORY) |
#include<stdio.h> |
|
3. |
Macro Definitions: After the header file section there is the symbolic
constant declaration section which also starts from # (Hess) Symbol and Macros are declared and
defined in this section (OPTIONAL) |
#define N 100 |
|
4. |
Global declaration section: this section is either before macros or after
macros and this section include both global data type declaration
(fundamental data type like int float, or functions declaration or defination
or arrays / structures declaration)(OPTIONAL) |
Int x=100; int add(){ |
|
5. |
Main function: Execution of the program starts here compiler recognizes
this statement as the execution point(COMPULSORY) |
void main() |
|
6. |
Data types/identifiers/ literals declaration and initialization: since C language is a strictly typed language thus before coding we have to decide all types of
variable names and constant names which we are going to use . after putting
the starting delimiter i.e. { |
{ int x; float y; double y=1000000; |
|
7. |
Processing section: this section we use for processing logic of the
program implemented here which gives us result followed by the ending
delimiter i.e. }
|
y=y/100; |
C CONVENTIONS:
- The name of the variables or even the C program must be started with an alphabet.
- The name should be eight characters long.
- The name must be started by alphabet then we can insert the numbers into it
- No special symbols or even space is allowed in the name.
- Only underscore allowed in the in names
- The name may be started by underscore but this practice must be avoided due to some keywords, names of which started by an underscore.
C TOKENS :
During programming, every word of the code represents a certain meaning to the compiler which comes into action while doing a compilation of the program, that words are called tokens. Basically, tokens are of the following types :
CHARACTER SETS
- Alphabets: From A to Z or a to z
- Digits: from 1 to 9 and 0
- Special characters it include all the symbols like +,&,~, etc
- Whitespace Characters The white spaces in the C programming language contain the following:
- Blank Spaces
- Carriage Return
- Tab
- New Line
TYPE
SYMBOL
Alphabet
a to =z A To Z
Numerical
0 – 9
Rithmetic
+ - *
Logical
!> <! &
Parenthesis
() {} []
Punctuation
: ; . ->
Special
= ‘ “ # /
IDENTIFIERS:
These are the sequence of characters that are given by the developer in order to identify the location created or checkpoints in the program. that is functions or the data objects. Such names follow the convention's rules which we have mentioned above.
KEYWORDS
These are the special words that are stored in the compiler in order to facilitate programming efficiency. We have to use these words according to their need or syntax. There are 32 keywords in C language and an increase as the new version is released.
SIMPLE DATA TYPES:
Data types - as name indicating that types of data used by the language in order to provide the information after processing it. language support different types of data indicates its power.
| various data types used in C |
MODIFIERS :
In C language different data types are used to store different values in the different memory locations created by the programmer Type modifiers are used to modify or add any special meaning to the predefined data types definition like 'l' used before d in conversion specification %ld or 'L' used before the conversion specification f that is %Lf.
- Short: Short modifier limits the user to store small integer values from -32768 to + 32767 it can be used only on integer data types
- Long: This type of modifier is used to convert the integer type of data or a small range of data to a bigger one of size 4 bytes and store the data value 9 million trillion. The syntax of declaration of such type is using long long instead of long int.
- Signed: Such modifier allows the user to store the value started from + positive to negative range
- Unsigned: values of such type of data are from 0 to its maximum range since unsigned may apply to integer and character types of data.
VARIABLE:
It is a named location in the memory of the computer to hold the value that can be changed by the program. These variables can take different values depending on their type and since C is strictly typed language thus all variables must be declared before they can be used. Variables can be defined on the basis of their size and on the basis of their allocation and initialization and also storage classes.
CONSTANTS :
Constants are the literals or the values which we try to change during the program executions but the system does not allow us to change them as they are declared so. Constants are basically of the different types as mentioned below :
As mentioned above the different types of data - constants are also stringing constants, character constants, numeric,floating-point constants
- Symbolic Constants: Declaration of such type of constants takes place using the #define symbol i.e. using the preprocessor directive we can define any symbol with a value and during compilation, the symbol replaces the value, and changes in the value of such symbol generates an error.
- Simple constants: The declaration of such constants takes place using the const keyword before the data type keyword the syntax of such declaration is <data type> <identifier>. like const float pi=3.14, as mentioned above constants, are always initialized at the time of the declaration.
OPERATOR PRECEDENCE
Operator precedence means the execution of the different operator on the basis of their priority for example the multiplication operator first calculated then addition or subtraction if there is a mixed mode of calculation.
INPUT AND OUTPUT OPERATORS :
Input operation means that values are taken by the program and stored at the location created by the programmer in the form of variable names. Actually, every program wants to communicate with the user in the form of certain values called the data which get stored in the locations created by the programmer. Language provides a certain function that helps us to do the same. these are printf and scanf functions
we can use the various forms of printf and scanf to do the input and output.
1. Printf is used in two forms: The first form is to print the string or group of characters like printf("\nthis is my first program in C language"); -- the argument placed in the double quotes printed on the output screen and escape sequence \n -- according to its definition that is a new line in output screen the output will be printed.
The other type of printf is used to print the value of the variable using the conversion specification that is printf("%d\n%d",a,b); -- this will print the value of a and b on the place where conversion specification is used
2. Scanf is used to take the value from the keyboard. the syntax of the scanf is -- scanf("conversion specification ",&variable name); -- this means the value entered by the keyboard extracted by the function and the address-of operator & will send the value at the address of that variable.
SINGLE CHARACTER INPUT AND OUTPUT :
The single character input and output functions are used in C language defined in the console and standard input output header file. such functions are following:
- getch function :
- getche
- putch
- gets
- puts
FORMATTED AND UNFORMATTED INPUT OUTPUT
The set of library functions that perform input and output operations is called standard input-output library.(stdio.h)while initializing the variable after declaration we can use two methods: the first one is to initialize the variable statically and the second one is to initialize the variable using some function i.e. during runtime and functions like scanf or etc. the list of conversion specification used to do such task are mentioned below.
|
DATA
TYPES |
BYTES STORED |
CONVERSION
SPECIFICATION |
|
Signed Char |
1 |
%c |
|
Unsigned char |
1 |
%c |
|
Short signed
int |
1 |
%h |
|
Unsigned short
int |
1 |
%h |
|
Unsigned int |
2 |
%d |
|
signed int |
2 |
%u |
|
Long signed
int |
4 |
%ld |
|
Long unsigned
int |
4 |
%lu |
|
Float |
4 |
%f, %e, %g |
|
Double |
8 |
%lf |
|
Long double |
10 |
%Lf |
|
String |
-- |
%s |
|
Short integer |
1 |
%h |
|
An octal
integer |
2 |
%o |
|
A hexadecimal
integer |
2 |
%x |
|
Hexadecimal,
decimal, octal |
2 |
%i |
- Reading input data : standard input output library provides a function to read all types of data -- scanf function having syntax -- scanf("conversion specification ",address1,address2).
like int x;
printf("Enter the value");
scanf("%d",&x);
here & is called address-of operator and %d is called conversion specification as all types of a conversion specification are mentioned in the above table.
like int x;
printf("Enter the value");
scanf("%d",&x);
here & is called address-of operator and %d is called conversion specification as all types of a conversion specification are mentioned in the above table.
- Writing input data :
________________________________________________________________________________
CONDITIONAL STATEMENT
The conditional statement means if the condition or the ternary or conditional operator. both follow the concept of the one condition having two branches one is true branch executed when the condition became true or false part if the condition becomes false.
Syntax of if the condition :
if(condition) {
true part statement ;
else
false pat state
syntax of nested if :
if(condition)
{true part statement;}
else
{ if(condition)
{true part statement;}
else
{if(condition)
{true part statement;}
else
{false part statement;}
}}
SWITCH STATEMENT
the switch statement is used in the case when we know the exact values of the condition.
GOTO STATEMENT
LOOPING
BREAK AND CONTINUE STATEMENT
. Frequently asked questions:
- General-purpose programming languages: a language in which we can design both stand-alone applications and the web application both directly or indirectly is called a general-purpose programming language
- Procedural approach It is one out of three software development approaches i.e. procedural, modular, and object-oriented, all three have some rules which decide their category.
- Modular software development approach: If functions are added in the procedural approach then it is called the modular approach.
- B language: A predecessor of C language having lack of byte addressability developed by Ken Thompson
- Compiler: It is a part of the operating system which help to convert the high-level language into the machine language
- Object-oriented approach: software development based on certain principles like abstraction, encapsulation, inheritance, polymorphism is called the object-oriented approach.
- Typed language: Variable declaration is just after the main function declaration and no variable declaration takes place in at another place of programming i.e. mid or last of the program.
- Structured language: The program is divided into small modules that make it easy to debug, test and manage the code.
- Draw the flowchart for the compilation of the C program
No comments:
Post a Comment