Inbound 5122355674798459563
Inbound 5122355674798459563
INTRODUCTION TO C
#include<stdio.h>
int main()
{
printf("\n Welcome to the world of C ");
return 0;
}
Pre-
Source File process
Compiler
Object
Files
Library Files
Library Executable
Compiler Files Linker Files
Source File Pre-
process Object
Files
Library Files
●it cannot include any special characters or signed short int 2 -32768 to 32767
punctuation marks (like #, $, ^, ?, ., etc) except the signed int 2 -32768 to 32767
short int 2 -32768 to 32767
underscore"_".
unsigned short int 0 to 65535
●There cannot be two successive underscores 2
●Keywords cannot be used as identifiers long int -2147483648 to 2147483647
4
●The names are case sensitive. So, example,
“FIRST” is different from “first” and “First”. unsigned long int
4
0 to 4294967295
DATA TYPES IN C
Monitor Data
● The scanf() is used to read formatted data from the keyboard. The syntax of the scanf() can be
given as,
scanf (“control string”, arg1, arg2, ………….argn);
● The control string specifies the type and format of the data that has to be obtained from the
keyboard and stored in the memory locations pointed by the arguments arg1, arg2,…, argn. The
prototype of the control string can be give as:
[=%[*][width][modifiers]type=]
● * is an optional argument that suppresses assignment of the input field. That is, it indicates that
data should be read from the stream but ignored (not stored in the memory location).
● width is an optional argument that specifies the maximum number of characters to be read.
● modifiers is an optional argument that can be h, l or L for the data pointed by the corresponding
additional arguments. Modifier h is used for short int or unsigned short int, l is used for long int,
unsigned long int or double values. Finally, L is used long double data values.
● Type is same as specifier in printf()
Subtraction - a - b result = a – b 6
© Oxford University Press 2012. All rights reserved.
Modulus % a % b result = a % b 0
RELATIONAL OPERATORS
Also known as a comparison operator, it is an operator that compares two values. Expressions that contain
relational operators are called relational expressions. Relational operators return true or false value, depending on
whether the conditional relationship between the two operands holds or not.
EQUALITY OPERATORS
● C language supports two kinds of equality operators to compare their operands for strict equality or inequality.
● They are equal to (==) and not equal to (!=) operator.
●
The equality operators have lower precedence than the relational operators.
OPERATOR MEANING
A B A &&B A B A || B
A !A
0 0 0 0 0 0
0 1 0 0 1 1 0 1
1 0 0 1 0 1
1 0
1 1 1 1 1 1
● The conditional operator operator (?:) is just like an if .. else statement that can be written within
expressions. The syntax of the conditional operator is exp1 ? exp2 : exp3
Here, exp1 is evaluated first. If it is true then exp2 is evaluated and becomes the result of the
expression, otherwise exp3 is evaluated and becomes the result of the expression.
For example, large = ( a > b) ? a : b
● Conditional operators make the program code more compact, more readable, and safer to use as it is
easier both to check and guarantee that the arguments that are used for evaluation.
● Conditional operator is also known as ternary operator as it is neither a unary nor a binary operator; it
takes three operands.
● The assignment operator is responsible for assigning values to the variables. While the equal sign (=) is the
fundamental assignment operator, C also supports other assignment operators that provide shorthand ways to
represent common variable assignments. They are shown in the table.
SIZEOF OPERATOR
●sizeof is a unary operator used to calculate the sizes of data types.
●It can be applied to all data types.
●The operator returns the size of the variable, data type or expression in bytes.
●'sizeof' operator is used to determine the amount of memory space that
the variable/expression/data type will take.
For example,
●sizeof(char) returns 1, that is the size of a character data type. If we have,
int a = 10;
unsigned int result;
result = sizeof(a);
then result = 2,
© Oxford University Press 2012. All rights reserved.
TYPE CONVERSION AND TYPE CASTING
● Type conversion and type casting of variables refers to changing a variable of one data type into another.
● While type conversion is done implicitly, casting has to be done explicitly by the programmer. We will discuss
both of them here.
● Type conversion is done when the expression has variables of different data types. So to evaluate the
expression, the data type is promoted from lower to higher level where the hierarchy of data types can be
given as: double, float, long, int, short and char.
● For example, type conversion is automatically done when we assign an integer value to a floating point
variable. For ex,
float x;
int y = 3;
x = y;
Now, x = 3.0,
●Type casting is also known as forced conversion. It is done when the value of a higher data type has to be
converted in to the value of a lower data type. For example, we need to explicitly type cast an integer variable
into a floating point variable.
float salary = 10000.00;
int sal;
sal = (int) salary;
●Typecasting can be done by placing the destination data type in parentheses followed by the variable
name that has to be converted.© Oxford University Press 2012. All rights reserved.