Overview of C Language
Introduction:
The C programming linguistic communication is a pop together with widely used programming linguistic communication for creating figurer programs. Programmers closed to the public encompass C because it gives maximum command together with efficiency to the programmer.
C is a structured programming linguistic communication developed past times Dennis Ritchie inwards 1970's at Bell Laboratories. It is i of the most pop figurer languages today because of its structure, high-level abstraction, machine independent feature. C linguistic communication was developed with UNIX operating system, thus it is strongly associated with UNIX, which is i of the most pop network operating arrangement inwards work today together with oculus of meshwork information superhighway. The C has at nowadays acquire a widely used professional person linguistic communication for diverse reasons.
• Easy to learn
• Structured language
• It produces efficient programs.
• It tin receive low-level activities.
• It tin survive compiled on a multifariousness of figurer platforms.
How is C Language Used?
• System programming is i of the most mutual work instance of this language. C is peculiarly known to survive the linguistic communication of the Linux operating system. In fact, almost every operating arrangement is implemented inwards C.
• Its broad availability, depression arrangement resources usage, speed, together with portability convey made it used inwards a broad arrive at of figurer platforms, from embedded systems together with mobile devices to supercomputers.
• Its speed makes it a practiced linguistic communication inwards guild to write compilers or interpreters for other languages. For example, the Haskell’s compiler is written inwards C.
• Even though it’s non equally mutual equally it i time was, yous tin write user applications inwards C. But higher degree languages such equally Java are ofttimes preferred today to write these, equally their additional layers of abstraction enable the programmer to rapidly write working programs.
Characteristics:
• There are a small, fixed release of keywords, including a total laid of catamenia of command primitives: for, while, if, do patch together with switch.
• More than i assignment may survive performed inwards a unmarried statement.
• There are a large release of arithmetical together with logical operators, such equally +, +=, ++, &, , etc.
Structure Of C Program:
• Documentation Section //optional
• Link department //optional
• Defining department //optional
• Global proclamation department //optional
• Main business office department //Must
{
Declaration share
Executable part.
}
• Sub plan department //optional
• Function 1
• Function 2
• Function n
What is Data Type?
A information type inwards a programming linguistic communication is a laid of information values having predefine characteristics. There are 3 classes of information types:
• Primitive
• Derived
• User define
Types of Data Type:
• In c linguistic communication compiler back upwardly 5 key information type namely integer (int), graphic symbol (char), floating dot (float), double together with void.
• Derived information types are array, structure, pointer, function.
• Influenza A virus subtype H5N1 user define information type is basically made past times the user itself.
Variables:
Variables are retentiveness place inwards computer's retentiveness to shop data. To betoken the retentiveness location, each variable should survive given a unique lift called identifier. Variable names are merely the symbolic representation of a retentiveness location. Examples of variable name: sum, car_no, count etc.
int num;
Here, num is a variable of integer type.
In C programming, yous convey to declare variable earlier using it inwards the program.
Constants:
Constants are the price that can't survive changed during the execution of a program. For example: 1, 2.5, "Programming is easy." etc. In C, constants tin survive classified as:
Integer constants:
Integer constants are the numeric constants(constant associated with number) without whatever fractional share or exponential part. There are 3 types of integer constants inwards C language: decimal constant(base 10), octal constant(base 8) together with hexadecimal constant (base 16).
Decimal digits: 0 1 2 3 four 5 6 seven viii 9
Octal digits: 0 1 2 3 four 5 6 7
Hexadecimal digits: 0 1 2 3 four 5 6 seven viii ix Influenza A virus subtype H5N1 B C D east F.
Floating-point constants:
Floating dot constants are the numeric constants that has either fractional shape or exponent form. For example:
-2.0
0.0000234
-0.22E-5
Character constants:
Character constants are the constant which work unmarried quotation closed to characters. For example: 'a', 'l', 'm', 'F' etc.
Escape Sequences:
Sometimes, it is necessary to work newline(enter), tab, quotation score etc. inwards the plan which either cannot survive typed or has special pregnant inwards C programming. In such cases, escape sequence are used. For example: \n is used for newline. The backslash(\) causes "escape" from the normal way the characters are interpreted past times the compiler.
String constants:
String constants are the constants which are enclosed inwards a duo of double-quote marks. For example:
"good" //string constant
"" //null string constant
" " //string constant of vi white space
"x" //string constant having unmarried character.
"Earth is round\n" //prints string with newline
Enumeration constants:
Keyword enum is used to declare enumeration types. For example:
enum color {yellow, green, black, white};
Here, the variable lift is color together with yellow, green, dark together with white are the enumeration constants having value 0, 1, 2 together with 3 respectively past times default.
Decision making inwards C:
Decision making is most deciding the guild of execution of statements based on for certain weather condition or repeat a grouping of statements until for certain specified weather condition are met. C linguistic communication handles decision-making past times supporting the next statements,
• if statement
• switch statement
• conditional operator statement
• goto statement
Decision making with if statement:
The if statement may survive implemented inwards dissimilar forms depending on the complexity of weather condition to survive tested. The dissimilar forms are,
• Simple if statement
• If....else statement
• Nested if....else statement
• else if statement
• Simple if statement
The full general shape of a elementary if statement is,
if (expression)
{
statement-inside;
}
statement-outside;
If the appear is true, thus 'statement-inside' it volition survive executed, otherwise 'statement-inside' is skipped together with alone 'statement-outside' is executed.
if...else statement:
The full general shape of a elementary if...else statement is,
if (expression)
{
statement-block1;
}
else
{
statement-block2;
}
If the 'expression' is true, the 'statement-block1' is executed, else 'statement-block1' is skipped together with 'statement-block2' is executed.
Nested if....else statement:
The full general shape of a nested if...else statement is,
if( appear )
{
if( expression1 )
{
statement-block1;
}
else
{
statement-block 2;
}
}
else
{
statement-block 3;
}
if 'expression' is fake the 'statement-block3' volition survive executed, otherwise it continues to perform the bear witness for 'expression 1' . If the 'expression 1' is truthful the 'statement-block1' is executed otherwise 'statement-block2' is executed.
else-if ladder:
The full general shape of else-if ladder is,
if(expression 1)
{
statement-block1;
}
else if(expression 2)
{
statement-block2;
}
else if(expression 3 )
{
statement-block3;
}
else
default-statement;
The appear is tested from the top(of the ladder) downwards. As before long equally the truthful status is found, the statement associated with it is executed.
Switch Case:
Switch statement is used to solve multiple selection type problems for carte similar program, where i value is associated with each option. The appear inwards switch instance evaluates to render an integral value, which is thus compared to the values inwards dissimilar cases, where it matches that block of code is executed, if in that place is no match, together with thus default block is executed. The full general shape of switch statement is,
syntax:
switch(expression)
{
case labels:
break;
}
Looping:
To execute a laid of instructions repeatedly until a detail status is existence satisfied.
A sequence of statements are executed until a specified status is true. This sequence of statements to survive executed is kept within the curly braces { } known equally the Loop body. After every execution of loop body, status is verified, together with if it is constitute to survive truthful the loop trunk is executed again. When the status banking concern check returns false, the loop trunk is non executed.There are 3 type of Loops inwards C language
• patch loop
• for loop
• do-while loop
while loop: patch loop tin survive addressed equally an entry command loop. It is completed inwards 3 steps.
• Variable initialization. (E.g. int x=0;)
• Condition (e.g. while(x<=10))
• Variable increment or decrement (x++ or x-- or x=x+2)
Syntax :
variable initialization ;
while (condition)
{
statements ;
variable increment or decrement ;
}
for loop: for loop is used to execute a laid of statements repeatedly until a detail status is satisfied. We tin say it an opened upwardly ended loop. General format is,
for(initialization; status ; increment/decrement)
{
statement-block;
}
In for loop nosotros convey just ii semicolons, i afterwards initialization together with instant afterwards condition. In this loop nosotros tin convey to a greater extent than than i initialization or increment/decrement, separated using comma operator. for loop tin convey alone i condition.
Nested for loop: We tin also convey nested for loops, i.e. i for loop within some other for loop. Basic syntax is,
for(initialization; condition; increment/decrement)
{
for(initialization; condition; increment/decrement)
{
statement ;
}
}
do patch loop: In some situations it is necessary to execute trunk of the loop earlier testing the condition. Such situations tin survive handled with the care of do-while loop. do statement evaluates the trunk of the loop offset together with at the end, the status is checked using patch statement. General format of do-while loop is,
do
{
....
.....
}
while(condition)
Jumping Out of Loops:
Sometimes, patch executing a loop, it becomes necessary to skip a share of the loop or to leave of absence the loop equally before long equally for certain status becomes true, that is called jumping out of loop. C linguistic communication allows jumping from i statement to some other within a loop equally good equally jumping out of the loop.
1) interruption statement:
When interruption statement is encountered within a loop, the loop is straightaway exited together with the plan continues with the statement straightaway next the loop.
2) pop off on statement:
It causes the command to pop off conduct to the test-condition together with thus pop off on the loop process. On encountering continue, cursor leave of absence the electrical current cycle of loop, together with starts with the side past times side cycle.
Array:
An array is a collection of elements of the same information type.In C language, arrays are referred to equally structured information types. An array is defined equally finite ordered collection of homogenous data, stored inwards contiguous retentiveness locations.
Here the words,
• finite agency information arrive at must survive defined.
• ordered agency information must survive stored inwards continuous retentiveness addresses.
• homogenous agency information must survive of similar information type.
Since arrays furnish an slow way to correspond data, it is classified with the information structures inwards C. Other information structures inwards c are structure, lists, queues together with trees. Array tin survive used to correspond non alone elementary listing of information but also tabular array of information inwards ii or 3 dimensions.
Syntax : information type arrayname[size];
Types of array:
• 1 dimensional
• 2 dimensional
• Multi-dimensional
1-dimensional: It is a linear listing of fixed release of information items of the same type. All these information items are accessed using the same lift using a unmarried subscript. It is similar to a row or column matrix. It is also called equally a single-dimensional Array or i subscripted variable.
Declaration:
The syntax of declaring a one-dimensional Array is equally follows:
data_type arrayname [size];
where,
arrayname => lift of the Array.
size => release of elements of same information type.
Two dimensional Arrays:
C linguistic communication supports multidimensional arrays. The simplest shape of the multidimensional array is the two-dimensional array.
Two-dimensional array is declared equally follows,
type array-name[row-size][column-size]
Example: int a[3][4];
Pointer:
A pointer is a variable that points to some other variable. This agency that a pointer holds the retentiveness address of some other variable. Put some other way, the pointer does non concur a value inwards the traditional sense; instead, it holds the address of some other variable. Influenza A virus subtype H5N1 pointer "points to" that other variable past times belongings a re-create of its address.
Because a pointer holds an address rather than a value, it has ii parts. The pointer itself holds the address. That address points to a value. There is the pointer together with the value pointed to.
Syntax: information type *ptrname;
Structure:Structure is a user-defined information type inwards C which allows yous to combine dissimilar information types to shop a detail type of record. Structure helps to create a complex information type inwards to a greater extent than meaningful way. It is somewhat similar to an Array. The alone divergence is that array is used to shop collection of similar datatypes patch construction tin shop collection of whatever type of data.
Structure is used to correspond a record. Suppose yous desire to shop tape of Student which consists of pupil name, address, curlicue release together with age.
Defining a structure:
struct keyword is used to define a structure. struct define a novel information type which is a collection of dissimilar type of data.
Syntax :
structstructure_name
{
//Statements
};
Functions inwards C:
A business office is a block of code that performs a detail task. There are times when nosotros demand to write a detail block of code for to a greater extent than than i time inwards our program. This may atomic number 82 to bugs together with irritation for the programmer. C linguistic communication provides an approach inwards which yous demand to declare together with define a grouping of statements i time together with that tin survive called together with used whenever required. This saves both fourth dimension together with space.
C functions tin survive classified into ii categories,
• Library functions
• User-defined functions
Types of functions inwards C:
• Library functions are those functions which are defined past times C library, instance printf (), scanf (), strcat () etc. You merely demand to include appropriate header files to work these functions. These are already declared together with defined inwards C libraries.
• User-defined functions are those functions which are defined past times the user at the fourth dimension of writing program. Functions are made for code reusability together with for saving fourth dimension together with space.
Benefits of Using Functions:
• It provides modularity to the program.
• Easy code Reusability. You merely convey to telephone telephone the business office past times its lift to work it.
• In instance of large programs with thousands of code lines, debugging together with editing becomes easier if yous work functions.
Function declaration:
General syntax of business office proclamation is,
return-type function-name (parameter-list);
Like variable together with an array, a business office must also survive declared earlier it’s called. Influenza A virus subtype H5N1 business office proclamation tells the compiler most a business office lift together with how to telephone telephone the function. The actual trunk of the business office tin survive defined separately.
File Handling:
A file represents a sequence of bytes on the disk where a grouping of related information is stored. File is created for permanent storage of data. It is a ready-made structure.
In C language, nosotros work a construction pointer of file type to declare a file.
FILE *fp;
Error Handling:
C linguistic communication does non furnish conduct back upwardly for fault handling. However few method together with variable defined inwards error.h header file tin survive used to dot out fault using render value of the business office call. In C language, a business office render -1 or NULL value inwards instance of whatever fault together with a global variable errno is laid with the fault code. So the render value tin survive used to banking concern check fault patch programming.
C linguistic communication uses the next functions to correspond error
• Perror() render string top to it along with the textual representation of electrical current errno value.
• Strerror() is defined inwards string.h library. This method returns a pointer to the string representation of the electrical current errno value.
Dynamic Memory Allocation:
The procedure of allocating retentiveness at runtime is known equally dynamic retentiveness allocation. Library routines known equally "memory management functions" are used for allocating together with freeing retentiveness during execution of a program. These functions are defined inwards stdlib.h.
• malloc (): allocates requested size of bytes together with returns a void pointer pointing to the offset byte of the allocated space
• calloc (): allocates infinite for an array of elements, initialize them to null together with thus render a void pointer to the memory
• free: releases previously allocated memory
• realloc: modify the size of previously allocated space
Command business Argument:
Command business statement is a parameter supplied to the plan when it is invoked. Command business statement is an of import concept inwards C programming. It is by together with large used when yous demand to command your plan from outside. Command business arguments are passed to master copy () method.
Syntax:
int main( int argc, char *argv[])
Here argc counts the release of arguments on the command business together with argv[ ] is a pointer array which holds pointers of type char which points to the arguments passed to the program.
Advantages:
Here are some advantages of programming inwards C:
• C is a full general purpose programming language, pregnant that it is non limited to whatever i specific variety of programming. This is dissimilar from languages similar COBOL which was built for concern applications, together with FORTRAN for scientific calculations. You tin write all sorts of software using C.
• C is non a really high-level language. Influenza A virus subtype H5N1 high-level linguistic communication tries to isolate the programmer from the hardware equally much equally possible. In contrast, C allows yous to conduct access retentiveness addresses, create fleck fields together with structures together with map them to memory, perform bitwise operations together with thus on. C facilitates hardware programming. .
• Not existence high-level also agency in that place is lilliputian overhead; it is highly efficient together with provides fast execution speed. .
• There are C linguistic communication compilers together with evolution tools available for many dissimilar platforms from small-scale embedded systems to large mainframes together with supercomputers. .
• C has been closed to for almost xl years. In that fourth dimension in that place has much software written inwards C. If in that place is some functionality yous demand inwards a C plan yous are writing, chances are individual has already written it. It may fifty-fifty survive available for free.
Sumber http://www.gcreddy.com/
Introduction:
The C programming linguistic communication is a pop together with widely used programming linguistic communication for creating figurer programs. Programmers closed to the public encompass C because it gives maximum command together with efficiency to the programmer.
C is a structured programming linguistic communication developed past times Dennis Ritchie inwards 1970's at Bell Laboratories. It is i of the most pop figurer languages today because of its structure, high-level abstraction, machine independent feature. C linguistic communication was developed with UNIX operating system, thus it is strongly associated with UNIX, which is i of the most pop network operating arrangement inwards work today together with oculus of meshwork information superhighway. The C has at nowadays acquire a widely used professional person linguistic communication for diverse reasons.
• Easy to learn
• Structured language
• It produces efficient programs.
• It tin receive low-level activities.
• It tin survive compiled on a multifariousness of figurer platforms.
How is C Language Used?
• System programming is i of the most mutual work instance of this language. C is peculiarly known to survive the linguistic communication of the Linux operating system. In fact, almost every operating arrangement is implemented inwards C.
• Its broad availability, depression arrangement resources usage, speed, together with portability convey made it used inwards a broad arrive at of figurer platforms, from embedded systems together with mobile devices to supercomputers.
• Its speed makes it a practiced linguistic communication inwards guild to write compilers or interpreters for other languages. For example, the Haskell’s compiler is written inwards C.
• Even though it’s non equally mutual equally it i time was, yous tin write user applications inwards C. But higher degree languages such equally Java are ofttimes preferred today to write these, equally their additional layers of abstraction enable the programmer to rapidly write working programs.
Characteristics:
• There are a small, fixed release of keywords, including a total laid of catamenia of command primitives: for, while, if, do patch together with switch.
• More than i assignment may survive performed inwards a unmarried statement.
• There are a large release of arithmetical together with logical operators, such equally +, +=, ++, &, , etc.
Structure Of C Program:
• Documentation Section //optional
• Link department //optional
• Defining department //optional
• Global proclamation department //optional
• Main business office department //Must
{
Declaration share
Executable part.
}
• Sub plan department //optional
• Function 1
• Function 2
• Function n
What is Data Type?
A information type inwards a programming linguistic communication is a laid of information values having predefine characteristics. There are 3 classes of information types:
• Primitive
• Derived
• User define
Types of Data Type:
• In c linguistic communication compiler back upwardly 5 key information type namely integer (int), graphic symbol (char), floating dot (float), double together with void.
• Derived information types are array, structure, pointer, function.
• Influenza A virus subtype H5N1 user define information type is basically made past times the user itself.
Variables:
Variables are retentiveness place inwards computer's retentiveness to shop data. To betoken the retentiveness location, each variable should survive given a unique lift called identifier. Variable names are merely the symbolic representation of a retentiveness location. Examples of variable name: sum, car_no, count etc.
int num;
Here, num is a variable of integer type.
In C programming, yous convey to declare variable earlier using it inwards the program.
Constants:
Constants are the price that can't survive changed during the execution of a program. For example: 1, 2.5, "Programming is easy." etc. In C, constants tin survive classified as:
Integer constants:
Integer constants are the numeric constants(constant associated with number) without whatever fractional share or exponential part. There are 3 types of integer constants inwards C language: decimal constant(base 10), octal constant(base 8) together with hexadecimal constant (base 16).
Decimal digits: 0 1 2 3 four 5 6 seven viii 9
Octal digits: 0 1 2 3 four 5 6 7
Hexadecimal digits: 0 1 2 3 four 5 6 seven viii ix Influenza A virus subtype H5N1 B C D east F.
Floating-point constants:
Floating dot constants are the numeric constants that has either fractional shape or exponent form. For example:
-2.0
0.0000234
-0.22E-5
Character constants:
Character constants are the constant which work unmarried quotation closed to characters. For example: 'a', 'l', 'm', 'F' etc.
Escape Sequences:
Sometimes, it is necessary to work newline(enter), tab, quotation score etc. inwards the plan which either cannot survive typed or has special pregnant inwards C programming. In such cases, escape sequence are used. For example: \n is used for newline. The backslash(\) causes "escape" from the normal way the characters are interpreted past times the compiler.
String constants:
String constants are the constants which are enclosed inwards a duo of double-quote marks. For example:
"good" //string constant
"" //null string constant
" " //string constant of vi white space
"x" //string constant having unmarried character.
"Earth is round\n" //prints string with newline
Enumeration constants:
Keyword enum is used to declare enumeration types. For example:
enum color {yellow, green, black, white};
Here, the variable lift is color together with yellow, green, dark together with white are the enumeration constants having value 0, 1, 2 together with 3 respectively past times default.
Decision making inwards C:
Decision making is most deciding the guild of execution of statements based on for certain weather condition or repeat a grouping of statements until for certain specified weather condition are met. C linguistic communication handles decision-making past times supporting the next statements,
• if statement
• switch statement
• conditional operator statement
• goto statement
Decision making with if statement:
The if statement may survive implemented inwards dissimilar forms depending on the complexity of weather condition to survive tested. The dissimilar forms are,
• Simple if statement
• If....else statement
• Nested if....else statement
• else if statement
• Simple if statement
The full general shape of a elementary if statement is,
if (expression)
{
statement-inside;
}
statement-outside;
If the appear is true, thus 'statement-inside' it volition survive executed, otherwise 'statement-inside' is skipped together with alone 'statement-outside' is executed.
if...else statement:
The full general shape of a elementary if...else statement is,
if (expression)
{
statement-block1;
}
else
{
statement-block2;
}
If the 'expression' is true, the 'statement-block1' is executed, else 'statement-block1' is skipped together with 'statement-block2' is executed.
Nested if....else statement:
The full general shape of a nested if...else statement is,
if( appear )
{
if( expression1 )
{
statement-block1;
}
else
{
statement-block 2;
}
}
else
{
statement-block 3;
}
if 'expression' is fake the 'statement-block3' volition survive executed, otherwise it continues to perform the bear witness for 'expression 1' . If the 'expression 1' is truthful the 'statement-block1' is executed otherwise 'statement-block2' is executed.
else-if ladder:
The full general shape of else-if ladder is,
if(expression 1)
{
statement-block1;
}
else if(expression 2)
{
statement-block2;
}
else if(expression 3 )
{
statement-block3;
}
else
default-statement;
The appear is tested from the top(of the ladder) downwards. As before long equally the truthful status is found, the statement associated with it is executed.
Switch Case:
Switch statement is used to solve multiple selection type problems for carte similar program, where i value is associated with each option. The appear inwards switch instance evaluates to render an integral value, which is thus compared to the values inwards dissimilar cases, where it matches that block of code is executed, if in that place is no match, together with thus default block is executed. The full general shape of switch statement is,
syntax:
switch(expression)
{
case labels:
break;
}
Looping:
To execute a laid of instructions repeatedly until a detail status is existence satisfied.
A sequence of statements are executed until a specified status is true. This sequence of statements to survive executed is kept within the curly braces { } known equally the Loop body. After every execution of loop body, status is verified, together with if it is constitute to survive truthful the loop trunk is executed again. When the status banking concern check returns false, the loop trunk is non executed.There are 3 type of Loops inwards C language
• patch loop
• for loop
• do-while loop
while loop: patch loop tin survive addressed equally an entry command loop. It is completed inwards 3 steps.
• Variable initialization. (E.g. int x=0;)
• Condition (e.g. while(x<=10))
• Variable increment or decrement (x++ or x-- or x=x+2)
Syntax :
variable initialization ;
while (condition)
{
statements ;
variable increment or decrement ;
}
for loop: for loop is used to execute a laid of statements repeatedly until a detail status is satisfied. We tin say it an opened upwardly ended loop. General format is,
for(initialization; status ; increment/decrement)
{
statement-block;
}
In for loop nosotros convey just ii semicolons, i afterwards initialization together with instant afterwards condition. In this loop nosotros tin convey to a greater extent than than i initialization or increment/decrement, separated using comma operator. for loop tin convey alone i condition.
Nested for loop: We tin also convey nested for loops, i.e. i for loop within some other for loop. Basic syntax is,
for(initialization; condition; increment/decrement)
{
for(initialization; condition; increment/decrement)
{
statement ;
}
}
do patch loop: In some situations it is necessary to execute trunk of the loop earlier testing the condition. Such situations tin survive handled with the care of do-while loop. do statement evaluates the trunk of the loop offset together with at the end, the status is checked using patch statement. General format of do-while loop is,
do
{
....
.....
}
while(condition)
Jumping Out of Loops:
Sometimes, patch executing a loop, it becomes necessary to skip a share of the loop or to leave of absence the loop equally before long equally for certain status becomes true, that is called jumping out of loop. C linguistic communication allows jumping from i statement to some other within a loop equally good equally jumping out of the loop.
1) interruption statement:
When interruption statement is encountered within a loop, the loop is straightaway exited together with the plan continues with the statement straightaway next the loop.
2) pop off on statement:
It causes the command to pop off conduct to the test-condition together with thus pop off on the loop process. On encountering continue, cursor leave of absence the electrical current cycle of loop, together with starts with the side past times side cycle.
Array:
An array is a collection of elements of the same information type.In C language, arrays are referred to equally structured information types. An array is defined equally finite ordered collection of homogenous data, stored inwards contiguous retentiveness locations.
Here the words,
• finite agency information arrive at must survive defined.
• ordered agency information must survive stored inwards continuous retentiveness addresses.
• homogenous agency information must survive of similar information type.
Since arrays furnish an slow way to correspond data, it is classified with the information structures inwards C. Other information structures inwards c are structure, lists, queues together with trees. Array tin survive used to correspond non alone elementary listing of information but also tabular array of information inwards ii or 3 dimensions.
Syntax : information type arrayname[size];
Types of array:
• 1 dimensional
• 2 dimensional
• Multi-dimensional
1-dimensional: It is a linear listing of fixed release of information items of the same type. All these information items are accessed using the same lift using a unmarried subscript. It is similar to a row or column matrix. It is also called equally a single-dimensional Array or i subscripted variable.
Declaration:
The syntax of declaring a one-dimensional Array is equally follows:
data_type arrayname [size];
where,
arrayname => lift of the Array.
size => release of elements of same information type.
Two dimensional Arrays:
C linguistic communication supports multidimensional arrays. The simplest shape of the multidimensional array is the two-dimensional array.
Two-dimensional array is declared equally follows,
type array-name[row-size][column-size]
Example: int a[3][4];
Pointer:
A pointer is a variable that points to some other variable. This agency that a pointer holds the retentiveness address of some other variable. Put some other way, the pointer does non concur a value inwards the traditional sense; instead, it holds the address of some other variable. Influenza A virus subtype H5N1 pointer "points to" that other variable past times belongings a re-create of its address.
Because a pointer holds an address rather than a value, it has ii parts. The pointer itself holds the address. That address points to a value. There is the pointer together with the value pointed to.
Syntax: information type *ptrname;
Structure:Structure is a user-defined information type inwards C which allows yous to combine dissimilar information types to shop a detail type of record. Structure helps to create a complex information type inwards to a greater extent than meaningful way. It is somewhat similar to an Array. The alone divergence is that array is used to shop collection of similar datatypes patch construction tin shop collection of whatever type of data.
Structure is used to correspond a record. Suppose yous desire to shop tape of Student which consists of pupil name, address, curlicue release together with age.
Defining a structure:
struct keyword is used to define a structure. struct define a novel information type which is a collection of dissimilar type of data.
Syntax :
structstructure_name
{
//Statements
};
Functions inwards C:
A business office is a block of code that performs a detail task. There are times when nosotros demand to write a detail block of code for to a greater extent than than i time inwards our program. This may atomic number 82 to bugs together with irritation for the programmer. C linguistic communication provides an approach inwards which yous demand to declare together with define a grouping of statements i time together with that tin survive called together with used whenever required. This saves both fourth dimension together with space.
C functions tin survive classified into ii categories,
• Library functions
• User-defined functions
Types of functions inwards C:
• Library functions are those functions which are defined past times C library, instance printf (), scanf (), strcat () etc. You merely demand to include appropriate header files to work these functions. These are already declared together with defined inwards C libraries.
• User-defined functions are those functions which are defined past times the user at the fourth dimension of writing program. Functions are made for code reusability together with for saving fourth dimension together with space.
Benefits of Using Functions:
• It provides modularity to the program.
• Easy code Reusability. You merely convey to telephone telephone the business office past times its lift to work it.
• In instance of large programs with thousands of code lines, debugging together with editing becomes easier if yous work functions.
Function declaration:
General syntax of business office proclamation is,
return-type function-name (parameter-list);
Like variable together with an array, a business office must also survive declared earlier it’s called. Influenza A virus subtype H5N1 business office proclamation tells the compiler most a business office lift together with how to telephone telephone the function. The actual trunk of the business office tin survive defined separately.
File Handling:
A file represents a sequence of bytes on the disk where a grouping of related information is stored. File is created for permanent storage of data. It is a ready-made structure.
In C language, nosotros work a construction pointer of file type to declare a file.
FILE *fp;
Error Handling:
C linguistic communication does non furnish conduct back upwardly for fault handling. However few method together with variable defined inwards error.h header file tin survive used to dot out fault using render value of the business office call. In C language, a business office render -1 or NULL value inwards instance of whatever fault together with a global variable errno is laid with the fault code. So the render value tin survive used to banking concern check fault patch programming.
C linguistic communication uses the next functions to correspond error
• Perror() render string top to it along with the textual representation of electrical current errno value.
• Strerror() is defined inwards string.h library. This method returns a pointer to the string representation of the electrical current errno value.
Dynamic Memory Allocation:
The procedure of allocating retentiveness at runtime is known equally dynamic retentiveness allocation. Library routines known equally "memory management functions" are used for allocating together with freeing retentiveness during execution of a program. These functions are defined inwards stdlib.h.
• malloc (): allocates requested size of bytes together with returns a void pointer pointing to the offset byte of the allocated space
• calloc (): allocates infinite for an array of elements, initialize them to null together with thus render a void pointer to the memory
• free: releases previously allocated memory
• realloc: modify the size of previously allocated space
Command business Argument:
Command business statement is a parameter supplied to the plan when it is invoked. Command business statement is an of import concept inwards C programming. It is by together with large used when yous demand to command your plan from outside. Command business arguments are passed to master copy () method.
Syntax:
int main( int argc, char *argv[])
Here argc counts the release of arguments on the command business together with argv[ ] is a pointer array which holds pointers of type char which points to the arguments passed to the program.
Advantages:
Here are some advantages of programming inwards C:
• C is a full general purpose programming language, pregnant that it is non limited to whatever i specific variety of programming. This is dissimilar from languages similar COBOL which was built for concern applications, together with FORTRAN for scientific calculations. You tin write all sorts of software using C.
• C is non a really high-level language. Influenza A virus subtype H5N1 high-level linguistic communication tries to isolate the programmer from the hardware equally much equally possible. In contrast, C allows yous to conduct access retentiveness addresses, create fleck fields together with structures together with map them to memory, perform bitwise operations together with thus on. C facilitates hardware programming. .
• Not existence high-level also agency in that place is lilliputian overhead; it is highly efficient together with provides fast execution speed. .
• There are C linguistic communication compilers together with evolution tools available for many dissimilar platforms from small-scale embedded systems to large mainframes together with supercomputers. .
• C has been closed to for almost xl years. In that fourth dimension in that place has much software written inwards C. If in that place is some functionality yous demand inwards a C plan yous are writing, chances are individual has already written it. It may fifty-fifty survive available for free.