Академический Документы
Профессиональный Документы
Культура Документы
void main()
{
printf("Hello, World! \n");
}
All C compilers support a variety of data types.
This enables the programmer to select the
appropriate data types as per the need of the
application. The type of a variable determines
how much space it occupies in storage.
C Data types can be classified as follows:
Alphabets: A Z Or a z
Digits: 0,1,2…..9
Special symbols: ~ ‘ @ & % _ { etc…
SIGNED CHARACTER UNSIGNED CHARACTER
Keyword
Variable
Constant
Operators
Special Characters
Strings
The following C statement consists of five tokens −
printf("Hello, World! \n");
printf
(
"Hello, World! \n"
)
;
The words which are reserved by C compiler
for some specific purpose are called
Keywords.
Each keyword has its own significance and is
used for some predefined purpose. These
reserved words may not be used as constants
or variables or any other identifier names.
There are 32 keywords in total.
C variable is a named location in a memory
where a program can manipulate the data.
The data is stored in the memory, and at the
time of execution it is fetched for carrying out
different operations on it.
The variable value keeps on changing at
different times during program execution.
int age;
const pi;
float marks;
Here,
Line 3 is declaration.
Line 4 is initialization.
The initialization of variable at run time is called
dynamic initialization. Dynamic refers to the process
during execution.
Eg.
Void main()
{
int a=10;
int b;
b=a*10;
}
Here b is initialized dynamically.
In a C program, the semicolon is a statement
terminator. That is, each individual statement
must be ended with a semicolon. It indicates
the end of one logical entity.
Eg.
printf(“Hello”);
Comments are like helping text in your C
program and they are ignored by the
compiler
There are two types of comments:
// single line
/* double line */
Example:
/* my first program in C */
You cannot have comments within comments
Whitespace is the term used in C to describe
blanks, tabs, newline characters and
comments.
Whitespace separates one part of a
statement from another and enables the
compiler to identify where one element in a
statement, such as int, ends and the next
element begins.
int age;
there must be at least one whitespace
character (usually a space) between int and
age for the compiler to be able to distinguish
them. On the other hand, in the following
statement −
fruit = apples + oranges; // get the total fruit
no whitespace characters are necessary
between fruit and =, or between = and apples,
Constants refer to fixed values that the
program may not alter during its execution.
These fixed values are also called literals.
Numeric Character
Constant Constant
Undefined variable
Missing semicolon
Function call missing
Function should have prototype
The program must be linked to the ‘C’ library. If
it fails in such case these errors are raised .
most common errors are:
Divide by zero
Null value
Garbage result in printing.
Compiling a C program is a multi-stage process.
At an overview level, the process can be split
into four separate stages:
Creation,
Preprocessing,
Compilation and linking,
Executing the program.
This will be used to type your program like
Windows Notepad. The files you create with
your editor are called the source files and
they contain the program source codes. The
source files for C programs are typically
named with the extension ".c".
The first stage of compilation is called
preprocessing. In this stage, lines starting
with a # character are interpreted by the
preprocessor as preprocessor commands.
The preprocessor program executes first
automatically before the compilation of the
program.
The source program contains statements that
are to be translated into object codes. These
object codes are suitable for execution by the
computer. If there is no error in the program,
compilation proceeds and translated
program stored with the .obj extension.
Linking puts together all other program files
and functions that are required by the
program. Eg. If a program is using pow()
function, then the object code for this
function should be brought from math.h
library.
Therefore, to produce an executable program,
the existing pieces have to be rearranged and
the missing ones filled in. This process is
called linking.
After compilation the executable code will be
loaded in the computer’s main memory is
executed. The loader performs this function.
This executes your program, printing any
results to the screen. At this stage there may
be run-time errors.
If so, you must return to edit your program
source, and recompile it, and run it again.
An operator is a symbol that tells the compiler to
perform specific mathematical or logical
functions. C language is rich in built-in operators
and provides the following types of operators −
Arithmetic Operators
Relational Operators
Logical Operators
Bitwise Operators
Assignment Operators
Misc Operators
Arithmetic operators are used to perform
numeric calculations like addition,
subtraction, multiplication, division etc.
Unary operators: (+ - ++ --)
The operators which work upon single operand
are called unary operator.
Binary operators: (+ - * / %)
The operators which work upon more than
one operand are called binary operator.
Increment ++: is used to increment value of
variable by one.
Eg.
a=++b;
a=b++;
Decrement --: is used to decrement value of
variable by one.
Eg.
a=--b;
a=b--;
Relational operators are used to provide the
relationship between two expressions.
If the relation is true then it returns a value 1
otherwise 0 for false.
The operators which are used to test relation
between two or more variables or
expressions. It provides logical true 1, if the
condition is true and 0 otherwise.
Bitwise operator works on bits and perform bit-
by-bit operation. These operators can
operate only on integer operands such as int,
char, short, long.
The assignment operator is used to assign value to a
variable.
Comma operator
Conditional operator
sizeof operator
The comma operator is used to separate two
or more expressions. It has lowest priority.
Eg.
a=10,b=20,c=30;
(a=10,b=20,c=a+b)
The conditional operator contains condition
followed by two statements or values. If the
condition is true, the first statement is
executed, otherwise the second statement is
executed.
Syntax:
Condition ? Expression 1 : Expression 2
Eg. printf(2==3?4:5);
This operator is used to find out the size
occupied by a variable.
Eg.
int a;
Printf(“%d”,sizeof(a));
Ans. 2
Type casting is a way to convert a variable
from one data type to another data type. For
example, if you want to store a 'long' value
into a simple integer then you can type cast
'long' to 'int'. You can convert the values from
one type to another explicitly using the cast
operator as follows −
(type_name) expression
#include <stdio.h>
main()
{
int sum = 17, count = 5; double mean;
mean = (double) sum / count;
printf("Value of mean : %f\n", mean );
}
Type casting is of two types:
output:- 80.000000