Basics of C
Basics of C
Basics of C
Syntax
Error?
Yes
Desired No
Result? Logical Errors?
Stop
Structure of a ‘C’ Program
Documentation Section
// Program to add two numbers.
/* It tells purpose of C program.
Or we can use it for multiple lines comments.*/
Link section
#include<stdio.h>
Definition section
#define PI 3.1414
Global Declaration Section
do if static while
Variables
• A variable is nothing but a name given to a storage area that our
programs can manipulate.
Type Description
char Typically a single octet(one byte). This is an integer type.
int The most natural size of integer for the machine.
float A single-precision floating point value.
double A double-precision floating point value.
void Represents the absence of type.
Constants
• A constant is a value or an identifier whose value cannot be
altered in a program. For example: 1, 2.5,
• As mentioned, an identifier also can be defined as a constant.
eg. const double PI = 3.14
• Here, PI is a constant. Basically what it means is that, PI and
3.14 is same for this program.
Integer constants
• A integer constant is a numeric constant (associated with
number) without any fractional or exponential part. There are
three types of integer constants in C programming:
• decimal constant(base 10)
• octal constant(base 8)
• hexadecimal constant(base 16)
Constants
Floating-point constants
• A floating point constant is a numeric constant that has either
a fractional form or an exponent form. For example:
2.0,0.0000234,-0.22E-5
Character constants
• A character constant is a constant which uses single quotation
around characters. For example: 'a', 'l', 'm', 'F'
String constants
• String constants are the constants which are enclosed in a
pair of double-quote marks. For example: "good" ,"x","Earth
is round\n"
Escape Sequences
Sometimes, it is necessary to use characters which cannot be typed or has special
meaning in C programming. For example: newline(enter), tab, question mark etc.
In order to use these characters, escape sequence is used.
• For example: \n is used for newline. The backslash ( \ ) causes "escape" from the
normal way the characters are interpreted by the compiler.Escape
Sequences Character
• \b Backspace
• \f Form feed
• \n Newline
• \r Return
• \t Horizontal tab
• \v Vertical tab
• \\ Backslash
• \' Single quotation mark
• \" Double quotation mark
• \? Question mark
• \0 Null character
Operators in C:An operator is a symbol which operates on a value or a
variable. For example: + is an operator to perform addition.