blogger Indonesia

Follow judhyns blog

Chapter 1: Introduction to the C Language

THE FIRST PROGRAM IN C

Introduction

The C program is a set of functions. The program execution begins by executing the function main (). You can compile the program and execute using Turbo C compiler or using the following commands in Unix/Linux:

$ cc   -o a a.c

where a.c is the file in which you have written the program. This will create an executable file named a.exe.

$./a.

This will execute the program.

Program

#include 
main()
{
printf("Hello \n"); /* prints Hello on standard output */ }
 
Output : Hello

Explanation

1. The program execution begins with the function main().

2. The executable statements are enclosed within a block that is marked by ‘{’ and ‘}’.

3. The printf() function redirects the output to a standard output, which in most cases is the output on screen.

4. Each executable statement is terminated by ‘;’

5. The comments are enclosed in ‘/*...*/

Variables

Introduction

When you want to process some information, you can save the values temporarily in variables. In the following program you can define two variables, save the values, and put the addition in the third variable.

Program

#include 
main()
{
int i,j,k; // Defining variables Statement A
i = 6;    // Statement B
j = 8;
k = i + j;
printf("sum of two numbers is %d \n",k); // Printing results
}
output : sum of two numbers is 14

Explanation

1. Statement A defines variables of the type integer. For each variable you have to attach some data type. The data type defines the amount of storage allocated to variables, the values that they can accept, and the operations that can be performed on variables.

2. The ‘ // ’ is used as single line comment.

3. The ‘%d’ is used as format specifier for the integer. Each data type has a format specifier that defines how the data of that data type will be printed.

4. The assignment operator is ‘=’ and the statement is in the format:

Var = expression;

Points to Remember

1. The variables are defined at the begining of the block.

2. The data type is defined at the begining of declaration and followed by a list of variables.

3. It is the data type that assigns a property to a variable.

No comments:

feed

PR Check

activesearchresults

judhyn's blog

 

http://www.judhyn.blogspot.com | |