Introduction to C Programming

The sequence of instructions which are given to execute a specific task is known as a Program. There are several programming languages in this emerging technology. But still ‘C’ exists. Do you want to know the importance of C?

The ‘C’ language is one of the most popular languages among programmers. C was developed in 1972 by Dennis Ritchie at Bell Telephone Laboratories. C is a Middle-level language. Before programming in C, you should know some basics of C.

C BASICS:

Character set

Tokens

Identifiers

Keywords

Constants

Data types

Variables

Operators

CHARACTER SET:

The characters are used to form words, numbers and expressions on which the program is run. The characters in C are grouped as:

White spaces consist of blank space, new line, form feed, horizontal tab, and carriage return. White spaces may be used to separate words, but are prohibited to use between the characters of keywords and identifiers.

TOKENS:

Token is the fundamental unit in c language. The smallest individual units in a C program are known as tokens.

IDENTIFIERS:

The identifier may be the name of a variable or a constant or a function. The identifiers may be of alphanumeric but it should start with an alphabet (or underscore) and followed by alphabets or numbers or alphanumeric characters. In turbo c, the maximum length of identifier is 31, but in Unix OS, there is no such limit. No special characters and empty spaces are allowed in defining an identifier except underscore. Underscores can be used in identifiers for better readability and for better understanding.

Examples for Valid identifiers: a, a1, area, area1, hello_world

Examples for Invalid identifiers: 1area, *star, hello*

KEYWORDS:

All keywords have fixed meanings and these meanings cannot be changed. Keywords should not be used as identifiers. The list of keywords are

auto

double

int

Struct

break

else

long

Switch

case

enum

register

Typedef

char

extern

return

Union

const

float

short

Unsigned

continue

for

signed

Void

default

goto

sizeof

Volatile

do

if

static

While

CONSTANTS:

The fixed values which do not vary during the execution of the program are called constants.

Numeric constants

Integer constants (whole numbers)

Real or floating point Constants (decimal numbers)

Character constants

Single character constants (a single character within single quotations)

String constants (set of characters within double quotations)

DATA TYPES:

char – a single character can be defined as a char data type. A single character occupies 8 bits (1 byte) in memory.

A variable is used to reserve the memory space in a computer and also to store the values in a program.

Variable declaration: dataType variableList;

variableList refers to the list of variables separated by comma.

Declaration statements must end with semicolon.

Some examples are:

int area;

char name,s1;

OPERATORS:

An operator is a symbol that is used to perform specific mathematical and logical operations. Operators are classified into many categories a

Assignment operators

Arithmetic operators

Relational operators

Logical operators

Increment and Decrement operators

Conditional operators

Bitwise operators

Special operators

Assignment operators are used to assign the values on right hand side to the variables on the left-hand side. Some examples for assignment operations are

a=15;

a+=15; (or) a=a+15;

Arithmetic operators are used to perform arithmetic operations such as addition, subtraction, multiplication, division.

+ addition

– subtraction

* multiplication

/ multiplication

% modulo division

Modulo division operator gives the remainder of the operator.

For example 5%3 gives 2(remainder)

Relational operators are used to compare 2 values.

< less than

> greater than

<= less than or equal to

>= greater than or equal to

== equal to

!= not equal to

Logical operators

&& logical AND

|| logical OR

! logical NOT

Increment operator is used to increment (add 1) the value. Increment operator is ++.

Decrement operator is used to decrement (subtract 1) the value. Decrement operator is –.

Prefix operator first increments/decrements the operand and then the result is assigned to the variable on the left.

Postfix operator assigns the value to variable on the left and then increments/decrements the operand.

Consider the following examples,

a=5;

b=a++;

The above expressions result the value of b is5.

a=5;

b=++a;

The above expressions result the value of b is 6.

Conditional operator is “?:”

(expr1) ? (expr2) : (expr3)

Expr1 is evaluated first, if it is true expr2 is evaluated and it becomes the value of the expression. If expr1 is false expr3 is evaluated by skipping expr2 and it becomes the value of the expression.

Consider the following example,

a=10;

b=5;

max=(a&gt;b)?a:b;

Bitwise operators are used for manipulating data at bit level. The term bitwise refers to the testing, setting or shifting of the actual bits in a byte or word. The bitwise operators are

& bitwise AND

| bitwise OR

^ bitwise Exclusive OR

~ bitwise Complement

<< Shift left

>> Shift right

Special operators are comma, sizeof operator, pointer operator (& and *) and member selection operators (. and >).

Kayalvizhi Ganesan

Web developer, Blogger, You-tuber and a learner. I am always open up for learning new things and sharing it with people. This Blog is to share the things which I have learnt. My goal is to help TYRO to become a PRO