Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the all-in-one-wp-security-and-firewall domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home/u956308407/domains/dipaktiwari.com/public_html/wp-includes/functions.php on line 6114

Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the wordpress-seo domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home/u956308407/domains/dipaktiwari.com/public_html/wp-includes/functions.php on line 6114
Introduction of C - Dipak Tiwari
‎introduction of c

Introduction of C

Share this content on

Introduction of C

  • C was developed by Dennis Ritchie in the year 1972 at Bell Laboratories.
  • C is a general-purpose computer programming language.
  • C is developed along with the UNIX operating system, was coded almost entirely in C.

Importance

  • It is a robust language whose set of built-in functions and operators can be used to write any complex program.
  • It is well suited for writing both system software, business applications and technologies.
  • Programs written in C are efficient and fast.
  • C language is well suited for structure programming or procedural programming, thus requiring the user to think of a problem in terms of function modules or blocks.

Sample C Program

main() {
/*——comment begins—–*/

printf(“Hello World!”);

/*——comment end—–*/
}

main()

The main() is a special function used by the C system to tell computer where the program starts.

Every program must have only one main function, the compiler cannot tell which one marks the beginning of the program.

The empty pair of parentheses immediately following main indicates that the function main has no arguments or parameters.

‘{‘ and ‘}’

The opening bace ‘{‘ in the second line marks the beginning of the function main and the closing bace ‘}’ in the last line indicates the end  of the function, the closing bace also marks the end of the program.

All the statements between these two braces form the function body. The function body contains a set of instructions to perform the given task.

Here function body contains three statements, out which only the printf line is an executable statement.

/* and */

/* and */ are known as comment lines.

These are used in a program to enhance its readability and understanding.

Comment lines are not executable statements and therefore anything between /* and */ is ignored by the compiler.

A comment can be inserted anywhere blank spaces can occur at the beginning, middle, or end of line, but never in the middle of a word.

Comments do not affect the execution speed and the size of a program. Comment help the programmers and other users in understanding the various functions and operations of a program and serve as an aid to debugging and testing.

printf()

printf() is a predefined function for printing output.

Predefined means that it is a functions that has already been written and compiled, and linked together with our program at the time of linking.

The printf() function causes everything between the starting and ending quotation marks to be printed out.

Here output will be:

Hello World!


Note that the print line ends with a semicolon.
Every statement in C should end with a semicolon (;) mark.

The information contained between the paranthese is called the argument of the function.

C does make a distinction between uppercase and lowercase letters. For example printf and PRINTF are not the same.

Structure of Programs

Documentation Section

Link Section

Definition Section

Global Declaration Section

main() Function Section

{

           Declaraction Part

           Executable Part

Subprogram section

           Function1

           Function2.      (User-defined functions)

           Functionn

1. Documentation Section:

The documentation section consist of a set of comment lines, were the name of the program, the author and other details for the programmer.

2. Link Section

The link section provides instructions to the compiler to link functions from the system library.

3. Definition Section

The definition section defines all symbolic constants.

4. Global Declaration Section

There are some variables that are used in more than one function. Such variables are known as global variables and are declared in the global declaration section that is outside of all the functions.

5. main() Function Section

C program must have one main() function section. This section contains two parts i) Declaration Part ii) Executable Part.

i) Desclaration Part: Declares all the variables used in the executable part.

ii) Executable Part: Least one statement in the executable part.

6. Subprogram Section

The subprogram section contains all the user-defined functions that are called in thev main function.

User-defined functions are generally placed immediately after the main(), although they may appear in any order.

All sections, except the main() section may be absent when they are not required.

Useful links


Share this content on