Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

C programming

Introduction

C is a general-purpose programming language developed at AT & T's Bell Telephone Laboratories (USA) in 1972 by Dennis Ritchie. Since it was originally designed for and implemented on the UNIX operating system, therefore, it is strongly associated with UNIX though nowadays it is running on almost all operating systems. Here are most common reasons why C is still so popular:

c tutorial

- C is one of the most popular programming languages of all time to create system software as well as application software.

- C is a standardized programming language with international standards.

- C is the base for almost all popular programming languages.

- C is one of the foundations for modern computer science and information technology.

- The language of choice for serious programming.

- Ease of understanding and learning, and one of the most commonly used programming languages in colleges and universities.

- Once students have learned C, then it will be easy for them to pick up any other languages.

Let's look at a simple application in C:

/*welcome.c (program name)*/
/*The following program displays the message "Welcome to C Programming"*
#include <stdio.h>
main()
{
printf("Welcome to C Programming");
}

Note

This program runs fine under GNU Gcc compiler. We have tested this in a Ubuntu Linux system. But if you are using any other compiler like Turbo C++, the program needs to be modified to be executed successfully. For the sake of simplicity, we have not included those additional stuff here.

Structure of the above C Program

Comments

Comments are a good way to better understanding of the program statements. In C programming language the comment entries start with a "/*" and terminate with "*/" at the end of the line. The compiler (a compiler is a computer program which translates source code written in a programming language into object code.) ignores the comment statements.

In the above program, the lines

/*welcome.c ( program name )*/
/*This program displays the message "Welcome to C Programming"*/

are comment lines.

#include directive

The #include directive instructs the compiler to include the contents of the file "stdio.h" (standard input-output header file) enclosed within angular brackets.

main() function

In C programming language the main() function serves a special purpose, it tells the compiler where the program start. Every C program must have one and only one main() function otherwise compiler can not understand the starting position of a program. The body of the main function surrounded by curly braces ( { } ). In the above program there is only one statement [ printf("Welcome to C Programming"); ] between the curly braces. Each statement in a C program terminated with a semicolon( ; ).

format of main function in c

Output using printf

The only executable statement in above program is : printf ("Welcome to C Programming"); which displays the enclosed text i.e.
Welcome to C Programming

Next: C Tutorial



C Programming: Tips of the Day

Static variable inside of a function in C

The scope of variable is where the variable name can be seen. Here, x is visible only inside function foo().

The lifetime of a variable is the period over which it exists. If x were defined without the keyword static, the lifetime would be from the entry into foo() to the return from foo(); so it would be re-initialized to 5 on every call.

The keyword static acts to extend the lifetime of a variable to the lifetime of the programme; e.g. initialization occurs once and once only and then the variable retains its value - whatever it has come to be - over all future calls to foo().

Ref : https://bit.ly/3fOq7XP