SlideShare a Scribd company logo
Basics of C
History of C
• Programming language developed at AT &T(American
Telephone &Telegraph) in USA at Bell Laboratories in 1972 by
Dennis Ritchie.
• Dennis Ritchie is known as the founder of C language.
• Before C we had BCPL(Basic Combined Programming
Language) and B.
• C was formalized in 1988 by ANSI(American National Standard
Institute).
• C was developed to overcome the problems of previous
languages such as B, BCPL, etc
• C has now become a widely used professional language for various reasons:
• Nobody can learn C++, Java directly.
• Easy to learn.
• Major parts of OS like Windows, UNIX,LINUX are still written in C.
• Computer games are written in C.
Features/Characteristics of C
1) Modularity: Ability to break down a large module into manageable sub modules is called modularity, that
is an important feature of structured programming language.
Advantages:
1) Projects can be completed in time.
2) Debugging can be easier & faster.
2) Portability: highly portable i.e. the C programs written for a computer can be run on other systems with
little or no modification.
3) Speed: C is also called as middle –level language because programs written in C language runs at a speed
matching to that of assemble language.so, C language has both the merits of HLL and LLL.
4) Extendability: The ability to extend the existing software by adding new features is called extendability.
A C program is basically a collection of functions that are supported by the C library. We can
continuously add our own functions to C library. With the availability of large number of functions,
the programming task becomes simpler.
5) Flexibility: C provides a lot of inbuilt functions . It can be used for a variety of applications.
Note: C is called structured programming language because to
solve a large problem, C programming language divides the
problem into smaller modules called functions or procedures each of
which handles a particular responsibility.
Executing a C Program
• Two things needed:
• Text Editor-will be used to type a program. Eg: Notepad,Vi.
• The C Compiler
• IDE-Integrated Development Environment
• Eg: Devc++,Eclipse,Netbeans
• The files created with editor are called source files and they contain the
program source code.
• The source files for C programs are typically named with the extension “.c”.
• The source code written in source file is the human readable source for
program.
• It needs to be compiled into machine language so that your CPU can actually
execute the program as per the instructions given.
• The compiler compiles the source codes into final executable programs.
Editor
SourceFilePgm.c
Preprocessor
Modified Source Code in RAM
Compiler
Program Object Code File pgm.obj
Linker
Executable File pgm.exe
Developing a C Program
The process of conversion from source code to machine executable code is a multi-step
process. (Stages of Conversion from .c to .exe)
• If there are no errors in the source code, the processes called compilation and linking produce an
executable file.
• Stage 1: Preprocessing
• A preprocessor is just a text substitution tool and it instructs the compiler to do required pre-
processing before the actual compilation.
1. Modifies the preprocessor directives embedded in the source code/inclusion of other files. All
preprocessor directives/commands begin with a hash symbol(#).
Example: # include <stdio.h> inserts a particular header file from another file.(.h files
contain some C declarations & macro definitions)
2. Strips comments & whitespaces from the code.
The preprocessor generates an expanded source code.
Stage 2: Compilation
• Performed by a program called the compiler.
• Checks for syntax errors and warnings.
• Translates the preprocessor source code into object code(machine code).
• Saves the program in another file with the same file name with the extension ‘.obj’.
• If any compiler errors are received, no object code file will be generated.
• An object code file will be generated if only warnings, not errors, are recieved.
Stage 3: Linking
• Combines the program object code with other object code to produce the file.
• The other object code can come from:
• Run-time library.
• Other libraries.
• Or object files that you have created.
Example: if using pow() function, then object code of this function should be brought from math.h
library & linked to main() program
• Saves the executable code(.exe) to a disk file.
Include Header File Section
Global Declaration Section
/*comments*/
int main(void)/*function name*/
{
/*comments*/
Declaration part
Executable part
return 0;
}
user-defined functions
{
body of the function
}
Structure of a C Program
Write a program to display message, “Hello World”
# include<stdio.h> ---- tells compiler about input and output functions(i.e printf &others)
# include<conio.h>
void main( ) ---- main function where program execution starts
{
/* My first program in C*/
printf(“n Hello World!”);
getch();
}
• The first line of the program #include<stdio.h> is a preprocessor command, which tells a
C compiler to include stdio.h file before going to actual compilation.
• The next line int main() is the main function where the program execution begins. /The
void specifies that it returns no value.
• The next line /*____*/ will be ignored by the compiler. Such lines are called comments in
the program.
• The next line printf(_____) is another function available in C which causes the message
“Hello, World!” to be displayed.
Note:
• getch() function asks for a single character. Until you press any key, it blocks the screen.
• If you run the C program many times, it will append the output in previous output.
• But, you can call clrscr() function to clear the screen.
void main()
{
clrscr();
printf( );
}
Programming Rules:
A programmer while writing a program should follow following rules:
i. Every program should have a main() function.
ii. C statements should be terminated by a semi-colon. At some places, a comma operator is permitted. If only a semi-
colon is placed it is treated as a statement.
For Example:
while(condition)
;
The above statement generates infinite loop. Without semi-colon the loop will not execute.
iii. An unessential semicolon if placed by the programmer is treated as an empty statement.
iv. All statements should be written in lowercase letters. Generally, uppercase letters are used only for symbolic
constants.
v. Blank spaces may be inserted between the words. This leads to improvement in the readability of the statements.
However, this is not applicable while declaring a variable, keyword, constant and function.
vi. It is not necessary to fix the position of statement in the program; i.e. a programmer can write the statements
anywhere between the two braces following the declaration part.
The user can also write one or more statements in one line separating them with a semicolon(;). Hence it is often
called a free-form language. The following statements are valid.
A=b+c;
d=b*c;
or
A=b+c; d=b*c;
vii. The opening and closing braces should be balanced i.e. if opening braces are four, closing braces should also be four.
Header Files
• A header file is a file containing C function declarations and macro definitions to be shared between several
source files.
• There are two types of header files:
• The files that the programmer writes.
• The files that comes with the compiler.
• We request to use a header file in our program by including it with the C preprocessing directive #include,
• A simple practice in C programs is that we keep all the constants , macros, system wide global variables, and
function prototypes in the header files & include that header file whenever it is required.
• Both the user and the system header files are included using the preprocessor directive #include.
• It has following two forms:
1. #include<file>
This form is used for system header files. It searches for a file named ’file’ in a standard list of system
directories.
2. #include “file”
This form is used for header files of your own programs. It searches for a file named ‘file’ in the
directory containing the current file.
S.No. Header File Functions Function Example
1 stdio.h Input,output & file operation functions printf( ),scanf( )
2 conio.h Console input & output functions clrscr( ), getch( )
3 alloc.h Memory allocation & related functions malloc( ),calloc( ),
realloc( )
4 graphics.h All graphic-related functions circle( ), bar3d( )
5 math.h Mathematical functions abs( ), sqrt( )
6 string.h String manipulation functions strcpy( ), strcat( )
7 bios.h BIOS accessing functions biosdisk( )
8 assert.h Contains macros and definitions void assert(int )
9 ctype.h Contains prototypes of functions which
test characters
isalpha(char)
10 time.h Contains date and time related functions asctime( )
The C Character Set
• C programming language supports a set of predefined characters. It has a
character set, which is categorized as:
C Character Set
Letters
Digits
Whitespaces
Special Characters
1. Letters
Both Capital A to Z and small a to z are treated as distinct.
2. Digits
All decimal digits from 0 to 9 are allowed.
3. Whitespaces(character or a set of characters that are used for formatting purposes)-to
make code easier to read.
Eg- Tab-paragraph formatting feature used to align text
backspace – ‘b’ horizontal tab- ‘t’
vertical tab – ‘v’ new line- ‘n’
form feed- ‘f’ backslash- ‘’
alert bell- ‘a’ carriage return- ‘r’
question mark- ‘?’ double quotes- ‘”’  is called escape character
octal number- ‘000’ hexadecimal no- ‘xhh’
If want to check for any of these whitespaces, use isspace( ) standard library function from ctype.h
4. Special Characters - In association with letters and digits, there are 28 special characters in C
, comma . period ; semi colon : colon ’ apostrophe ” quotation marks
! Exclamation marks ~ Tilde < less than > greater than { } braces
% percent sign # number sign = equal to @ at the rate + plus sign
[ ] brackets ( ) parentheses - minus sign * Asterix ^ caret & ampersand
? Question mark $ dollar _ underscore  backslash / slash | vertical bar
The characters listed are represented in the computer by numeric values. Each character is assigned a
unique numeric value. These values put together are called character codes, which are used in the
computer system.
The widely used computer codes- ASCII, EBCDIC.
ASCII- American Standard Code for Information Interchange.
7 bits – 27 = 128 different characters
8 bits – 28 = 256 different characters
A - Z a - z
65 90 97 122
Delimiters: (a programming language uses delimiters to mark code , data & instructions
boundaries
C uses special kind of symbols which are called delimiters.
Delimiters Symbols Uses
Colon : Useful for labels
Semi-colon ; Terminates statements
Parenthesis ( ) Used in expressions & statements
Square brackets [ ] Used for array & declarations
Curly braces { } Scope of statements
Hash # Preprocessor directives
Comma , Variable separator
Types of Tokens:
• The smallest unit in a program/statement is called a token.
• The compiler views a program in terms of token.
• Example: The following C statement consists of five tokens:-
printf(“n Hello World”);
The individual tokens are-
printf- keyword
( - special character
“n Hello World” string
) special character
; special character
Tokens
Keywords
Variables
Operators
Constants
Special Characters
String
1. Keywords:
• words reserved by the compiler.
• 32 keywords by ANSCI standard.
2. Variables:
• User-defined words.
• Used to store values.
• Any number of variables can be defined.
3. Constants:
• Words whose values cannot be changed for the entire program run once assigned.
4. Operators:
• Used in expressions.
5. Special Characters:
• Used in declarations in C.
6. Strings:
• A sequence of characters.
C Keywords:
• are reserved words by the compiler.
• Words whose meaning has already been explained to the C compiler.
• Have been assigned fixed meanings-cannot change
• Cannot be used as variable names.
• For utilizing the keywords in a program, no header file is required to be included.
• ANSI C provides 32 keywords.
• Example: 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.
Identifiers:( symbolic names to refer to variable/function/constant)
• An identifier is a name used to identify a variable,constant,function, or any other user-defined
item.[like structure,union etc]
• User-defined names.
Rules:
• An identifier always starts with a letter A to Z, a to z, or an underscore ‘_’ followed by zero or more
letters,underscores, and digits(0-9).
• C identifiers does not allow blank spaces, punctuation such as @, $ and %.
• C is a case-sensitive language.
• Thus, Manpower and manpower are two different identifiers.
[ _ is used as a link between two words for the long identifiers]
• Valid identifiers: length, area_square, sUm_temp1.
• Invalid identifiers: S+um, year’s, length area.
• User-defined Identifiers: (i) # define N 10
(ii) # defne a 15
printf & scanf in C
The printf( ) and scanf( ) functions are used for input and output in C language. Both functions are inbuilt
library functions, defined in stdio.h(header file)
1. printf ( ) function:
• The printf( ) function is used for output.
• It prints the given statement to the console.
• The syntax of printf( )-
printf(“format string”, argument-list);
The format string can be %d(integer)
%c(character)
%s(string)
%f(float) etc
2. scanf( ) function
• The scanf( ) function is used for input.
• It reads the input data from the console.
• The syntax of scanf( )-
scanf(“format string”, argument-list);
• Example: scanf(“%d”,&number);
Program to print cube of a given number:
#include<stdio.h>
#include<conio.h>
void main( )
{
int number;
clrscr( );
printf(“Enter a number:”);
scanf(“%d”,&number);
printf(“Cube of number is %d”, number*number*number);
getch( );
}
Program to print sum of two numbers:
#include<stdio.h>
#include<conio.h>
void main( )
{
int x=0,y=0,result=0;
clrscr( );
printf( “Enter first number:”);
scanf(“%d”, &x);
printf(“Enter second number”);
scanf(“%d”, &y);
result=x+y;
printf(“sum of 2 numbers: %d”, result);
getch( );
}
Data Types:
• Variable-named memory location, value keeps varying-not fixed
• Every variable has a corresponding data type associated with it.
• In C, it is mandatory that every variable has a data type
• Why should a variable have a data type?
1. What is the kind of data that will be stored on that location. Eg, int-only numerical values can be
stored.
2. How much memory should be allocated for a variable. Eg int-2 bytes, short-2 bytes, long-4 bytes.
Eg a/10 –a is alphabet : compiler should give error-will do that on basis of data type of variables.
Eg int a=5,int b=2 then a/b will evaluate to 2 not 2.5 because both are integers.
Hence,
• Expressions are validated based on data type.
• Expressions are evaluated based on data type.
• Memory is allocated based on data type.
• Kind of data that will be stored on that location is done based on data type.
Variables:
• Named memory location.
• So you can refer to the data stored at that location using the name rather than address.
In C, variable names must adhere to following rules:
1. The names can contain letters,digits & the underscore character(_).
2. The first character of the name must be a letter. The underscore is also a legal first character , but its use is not
recommended.
3. No punctuation marks or blanks are allowed within a variable name.
4. Case matters i.e. upper & lowercase are different.
5. C keywords can’t be used as variable names.
Declaring:
• A variable definition means to tell the compiler where & how much to create the storage for the variable.
• A variable definition specifies a data type & contains a list of one or more variables of that type:
Type variable_list;
Example: int a,b;
• The declaration of the variables should be done in declaration part of the program.
• The variables must be declared before they are used in the program.
• Declaration ensures two things:
1. Compiler obtains the variables name.
2. It tells to the compiler data types of the variable being declared & helps in allocation of memory.
Initializing variables:
• Variables declared be assigned or initialized using assignment operator ‘=’.
• The declaration & initialization can also be done in the same line.
• Syntax:
• variable_name =constant;
Or
• data_type variable_name=constant;
• Example: int x=5;
int x=y=z=3;
int x,y,z;
x=y=z=3;
Dynamic Initialization:
• The initialization of variable at run time is called dynamic initialization[during execution].
• In C, initialization can be done at any place in the program; however the declaration should be done at the declaration
part only.
• Example: void main()
{
int r=2;
float area=3.14*r*r; //area is calculated & assigned to variable area
clrscr( );
printf(“Area= %f”,area); // the expression is solved at run time & assigned to area at run time.
}
C Data Types
Derived Basic User-Defined
-Pointer -Structure
-Function -Union
-Arrays -Enumeration
-Typedef
Integer Floating point void
-char -float
-int -double
Constants:
• Do not change during the execution of the program.
Constants
Numeric Character
Constant Constant
-Integer Constant -Character Constant
-Real Constant -String Constant
1. Integer Constants:
• These are a sequence of numbers from 0 to 9 without decimal points or fractional part or any other
symbol.
• It requires minimum 2 bytes & maximum 4 bytes.
• Integer constant could be either +ve and –ve or maybe zero.
• The number without a sign is assumed as positive.
• Eg -10,20,+30 etc
• Can also be represented in octal & hexadecimal no.s
2. Real Constants:
• Often known as floating-point constants.
• For representing many quantities, integer constants are not fit. Eg height, distance, weight.
• General format: mantissa & exponent.
Character Constants:
1. Single Character Constant:
• A character constant is a single character.
• It can be represented with single digit or a single special symbol or whitespace enclosed within a pair
of single quote marks.
• Eg ‘8’, ‘a’, ‘-’
• Length of a character, at the most, is one character.
• Character constants have integer values known as ASCII values.
• For eg, printf(“%c %d”, 65, ‘B’); --- ‘A’ & 66
2. String Constants:
• Sequence of characters enclosed within double quote marks.
• The string may be a combination of all kinds of symbols.
• For eg, “Hello”, “India” , “444”, “a”.
Preprocessor Constants:
Named constants may also be created using preprocessor.
#define SUNDAY 0
..
..
..
int day=SUNDAY;
Constant Variable:
• If we want the value of a certain variable to remain the same or unchanged during the program
execution, it can be done by declaring the variable as a constant.
• The keyword const is then prefixed before the declaration. It tells the compiler that the variable is
a constant.
• Thus, constant declared variable are protected from modification.
• Eg const int m=10;
Where const is a keyword, m is a variable name & 10 is a constant.
• The compiler protects the value of ‘m’ from modification.
• The user cannot assign any value to ‘m’.
Volatile Variable:
• The volatile variables are those variables that can be changed at any time by other external program or the
same program.
• Eg volatile int d;
Type Conversion (promoting lower type to higher type):
• Implicit
• Explicit
void main( )
{
printf(“two integer division : %d”, 5/2);
printf(“one integer & one float: %f”,5.5/2);
printf(“two integers: %f”, (float)5/2);
}
Third case- Both value are of type int.The result obtained is converted to float. –used type casting
(putting data type in a pair of parenthesis before operands. The programmer can specify any data type.
i. int x=3.5; --- x will be assigned 3, 0.5 will be lost.
ii. int x =35425 – will give unexpected result coz >32768
Invalid:
int =long
int =float
long=float
float=double
Valid:
long=int
double=float
int=char
Type Modifiers:
• The keywords signed, unsigned, short & long are type modifiers.
• A type modifier changes the meaning of basic data type & produces a new data type.
• Each of these type modifiers is applicable to the basic data type int.
• The modifiers signed &unsigned are also applicable to the type char.
• The long type modifier can be applicable to the double type.
• Int(signed) –both +ve and –ve
• Unsigned int –restricts to +ve values
Format Specifier
%c
%c
%c
%d or %i
%u
%d
%u
%ld
%lu
%f
%lf
%lf
Range= -2n-1 to 2 n-1 -1
• printf(“%f ”, 1.123456789);--more than 6
• Hence, output will be 1.123457(internally got converted to float, got rounded
off & truncated)
int a=10.5;
printf(“%d”,a);
Wrapping Around
void main( )
{
unsigned int u=65537;
clrscr( );
printf(“n u=%u”,u);
}
Output=1
The unsigned integer u=65537; after reaching the last range 65535, the compiler starts
from beginning. Hence, 1 is displayed. The value 65536 refers to 0 & 65537 to 1.

More Related Content

Similar to Basics of C Lecture 2[16097].pptx

C_Intro.ppt
C_Intro.pptC_Intro.ppt
C_Intro.ppt
gitesh_nagar
 
Introduction to C programming
Introduction to C programmingIntroduction to C programming
Introduction to C programming
Rokonuzzaman Rony
 
Introduction-to-C-Part-1.pdf
Introduction-to-C-Part-1.pdfIntroduction-to-C-Part-1.pdf
Introduction-to-C-Part-1.pdf
AnassElHousni
 
C Programming UNIT 1.pptx
C Programming  UNIT 1.pptxC Programming  UNIT 1.pptx
C Programming UNIT 1.pptx
Mugilvannan11
 
67404923-C-Programming-Tutorials-Doc.pdf
67404923-C-Programming-Tutorials-Doc.pdf67404923-C-Programming-Tutorials-Doc.pdf
67404923-C-Programming-Tutorials-Doc.pdf
Rajb54
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
Anandhasilambarasan D
 
Introduction to cpp language and all the required information relating to it
Introduction to cpp language and all the required information relating to itIntroduction to cpp language and all the required information relating to it
Introduction to cpp language and all the required information relating to it
PushkarNiroula1
 
Prog1-L1.pdf
Prog1-L1.pdfProg1-L1.pdf
Prog1-L1.pdf
valerie5142000
 
Object oriented programming 7 first steps in oop using c++
Object oriented programming 7 first steps in oop using  c++Object oriented programming 7 first steps in oop using  c++
Object oriented programming 7 first steps in oop using c++
Vaibhav Khanna
 
chapter 1.pptx
chapter 1.pptxchapter 1.pptx
chapter 1.pptx
SeethaDinesh
 
Introduction to C Language (By: Shujaat Abbas)
Introduction to C Language (By: Shujaat Abbas)Introduction to C Language (By: Shujaat Abbas)
Introduction to C Language (By: Shujaat Abbas)
Shujaat Abbas
 
The C++ Programming Language
The C++ Programming LanguageThe C++ Programming Language
The C++ Programming Language
Prof Ansari
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
marvellous2
 
C intro
C introC intro
C intro
Mohit Patodia
 
C programming
C programming C programming
C programming
Rohan Gajre
 
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTTC programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
Batra Centre
 

Similar to Basics of C Lecture 2[16097].pptx (20)

C_Intro.ppt
C_Intro.pptC_Intro.ppt
C_Intro.ppt
 
Introduction to C programming
Introduction to C programmingIntroduction to C programming
Introduction to C programming
 
Introduction-to-C-Part-1.pdf
Introduction-to-C-Part-1.pdfIntroduction-to-C-Part-1.pdf
Introduction-to-C-Part-1.pdf
 
C Programming UNIT 1.pptx
C Programming  UNIT 1.pptxC Programming  UNIT 1.pptx
C Programming UNIT 1.pptx
 
67404923-C-Programming-Tutorials-Doc.pdf
67404923-C-Programming-Tutorials-Doc.pdf67404923-C-Programming-Tutorials-Doc.pdf
67404923-C-Programming-Tutorials-Doc.pdf
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
Introduction to cpp language and all the required information relating to it
Introduction to cpp language and all the required information relating to itIntroduction to cpp language and all the required information relating to it
Introduction to cpp language and all the required information relating to it
 
Prog1-L1.pdf
Prog1-L1.pdfProg1-L1.pdf
Prog1-L1.pdf
 
C language unit-1
C language unit-1C language unit-1
C language unit-1
 
C LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDY
C LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDYC LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDY
C LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDY
 
C languaGE UNIT-1
C languaGE UNIT-1C languaGE UNIT-1
C languaGE UNIT-1
 
Object oriented programming 7 first steps in oop using c++
Object oriented programming 7 first steps in oop using  c++Object oriented programming 7 first steps in oop using  c++
Object oriented programming 7 first steps in oop using c++
 
chapter 1.pptx
chapter 1.pptxchapter 1.pptx
chapter 1.pptx
 
Introduction to C Language (By: Shujaat Abbas)
Introduction to C Language (By: Shujaat Abbas)Introduction to C Language (By: Shujaat Abbas)
Introduction to C Language (By: Shujaat Abbas)
 
The C++ Programming Language
The C++ Programming LanguageThe C++ Programming Language
The C++ Programming Language
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
C PROGRAMMING
C PROGRAMMINGC PROGRAMMING
C PROGRAMMING
 
C intro
C introC intro
C intro
 
C programming
C programming C programming
C programming
 
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTTC programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
 

Recently uploaded

Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
Ortus Solutions, Corp
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
informapgpstrackings
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
kalichargn70th171
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
e20449
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 

Recently uploaded (20)

Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 

Basics of C Lecture 2[16097].pptx

  • 2. History of C • Programming language developed at AT &T(American Telephone &Telegraph) in USA at Bell Laboratories in 1972 by Dennis Ritchie. • Dennis Ritchie is known as the founder of C language. • Before C we had BCPL(Basic Combined Programming Language) and B. • C was formalized in 1988 by ANSI(American National Standard Institute). • C was developed to overcome the problems of previous languages such as B, BCPL, etc
  • 3. • C has now become a widely used professional language for various reasons: • Nobody can learn C++, Java directly. • Easy to learn. • Major parts of OS like Windows, UNIX,LINUX are still written in C. • Computer games are written in C.
  • 5. 1) Modularity: Ability to break down a large module into manageable sub modules is called modularity, that is an important feature of structured programming language. Advantages: 1) Projects can be completed in time. 2) Debugging can be easier & faster. 2) Portability: highly portable i.e. the C programs written for a computer can be run on other systems with little or no modification. 3) Speed: C is also called as middle –level language because programs written in C language runs at a speed matching to that of assemble language.so, C language has both the merits of HLL and LLL. 4) Extendability: The ability to extend the existing software by adding new features is called extendability. A C program is basically a collection of functions that are supported by the C library. We can continuously add our own functions to C library. With the availability of large number of functions, the programming task becomes simpler. 5) Flexibility: C provides a lot of inbuilt functions . It can be used for a variety of applications.
  • 6. Note: C is called structured programming language because to solve a large problem, C programming language divides the problem into smaller modules called functions or procedures each of which handles a particular responsibility.
  • 7. Executing a C Program • Two things needed: • Text Editor-will be used to type a program. Eg: Notepad,Vi. • The C Compiler • IDE-Integrated Development Environment • Eg: Devc++,Eclipse,Netbeans
  • 8. • The files created with editor are called source files and they contain the program source code. • The source files for C programs are typically named with the extension “.c”. • The source code written in source file is the human readable source for program. • It needs to be compiled into machine language so that your CPU can actually execute the program as per the instructions given. • The compiler compiles the source codes into final executable programs.
  • 9. Editor SourceFilePgm.c Preprocessor Modified Source Code in RAM Compiler Program Object Code File pgm.obj Linker Executable File pgm.exe Developing a C Program
  • 10. The process of conversion from source code to machine executable code is a multi-step process. (Stages of Conversion from .c to .exe) • If there are no errors in the source code, the processes called compilation and linking produce an executable file. • Stage 1: Preprocessing • A preprocessor is just a text substitution tool and it instructs the compiler to do required pre- processing before the actual compilation. 1. Modifies the preprocessor directives embedded in the source code/inclusion of other files. All preprocessor directives/commands begin with a hash symbol(#). Example: # include <stdio.h> inserts a particular header file from another file.(.h files contain some C declarations & macro definitions) 2. Strips comments & whitespaces from the code. The preprocessor generates an expanded source code.
  • 11. Stage 2: Compilation • Performed by a program called the compiler. • Checks for syntax errors and warnings. • Translates the preprocessor source code into object code(machine code). • Saves the program in another file with the same file name with the extension ‘.obj’. • If any compiler errors are received, no object code file will be generated. • An object code file will be generated if only warnings, not errors, are recieved. Stage 3: Linking • Combines the program object code with other object code to produce the file. • The other object code can come from: • Run-time library. • Other libraries. • Or object files that you have created. Example: if using pow() function, then object code of this function should be brought from math.h library & linked to main() program • Saves the executable code(.exe) to a disk file.
  • 12. Include Header File Section Global Declaration Section /*comments*/ int main(void)/*function name*/ { /*comments*/ Declaration part Executable part return 0; } user-defined functions { body of the function } Structure of a C Program
  • 13. Write a program to display message, “Hello World” # include<stdio.h> ---- tells compiler about input and output functions(i.e printf &others) # include<conio.h> void main( ) ---- main function where program execution starts { /* My first program in C*/ printf(“n Hello World!”); getch(); } • The first line of the program #include<stdio.h> is a preprocessor command, which tells a C compiler to include stdio.h file before going to actual compilation. • The next line int main() is the main function where the program execution begins. /The void specifies that it returns no value. • The next line /*____*/ will be ignored by the compiler. Such lines are called comments in the program. • The next line printf(_____) is another function available in C which causes the message “Hello, World!” to be displayed.
  • 14. Note: • getch() function asks for a single character. Until you press any key, it blocks the screen. • If you run the C program many times, it will append the output in previous output. • But, you can call clrscr() function to clear the screen. void main() { clrscr(); printf( ); }
  • 15. Programming Rules: A programmer while writing a program should follow following rules: i. Every program should have a main() function. ii. C statements should be terminated by a semi-colon. At some places, a comma operator is permitted. If only a semi- colon is placed it is treated as a statement. For Example: while(condition) ; The above statement generates infinite loop. Without semi-colon the loop will not execute. iii. An unessential semicolon if placed by the programmer is treated as an empty statement. iv. All statements should be written in lowercase letters. Generally, uppercase letters are used only for symbolic constants. v. Blank spaces may be inserted between the words. This leads to improvement in the readability of the statements. However, this is not applicable while declaring a variable, keyword, constant and function. vi. It is not necessary to fix the position of statement in the program; i.e. a programmer can write the statements anywhere between the two braces following the declaration part. The user can also write one or more statements in one line separating them with a semicolon(;). Hence it is often called a free-form language. The following statements are valid. A=b+c; d=b*c; or A=b+c; d=b*c; vii. The opening and closing braces should be balanced i.e. if opening braces are four, closing braces should also be four.
  • 16. Header Files • A header file is a file containing C function declarations and macro definitions to be shared between several source files. • There are two types of header files: • The files that the programmer writes. • The files that comes with the compiler. • We request to use a header file in our program by including it with the C preprocessing directive #include, • A simple practice in C programs is that we keep all the constants , macros, system wide global variables, and function prototypes in the header files & include that header file whenever it is required. • Both the user and the system header files are included using the preprocessor directive #include. • It has following two forms: 1. #include<file> This form is used for system header files. It searches for a file named ’file’ in a standard list of system directories. 2. #include “file” This form is used for header files of your own programs. It searches for a file named ‘file’ in the directory containing the current file.
  • 17. S.No. Header File Functions Function Example 1 stdio.h Input,output & file operation functions printf( ),scanf( ) 2 conio.h Console input & output functions clrscr( ), getch( ) 3 alloc.h Memory allocation & related functions malloc( ),calloc( ), realloc( ) 4 graphics.h All graphic-related functions circle( ), bar3d( ) 5 math.h Mathematical functions abs( ), sqrt( ) 6 string.h String manipulation functions strcpy( ), strcat( ) 7 bios.h BIOS accessing functions biosdisk( ) 8 assert.h Contains macros and definitions void assert(int ) 9 ctype.h Contains prototypes of functions which test characters isalpha(char) 10 time.h Contains date and time related functions asctime( )
  • 18. The C Character Set • C programming language supports a set of predefined characters. It has a character set, which is categorized as: C Character Set Letters Digits Whitespaces Special Characters
  • 19. 1. Letters Both Capital A to Z and small a to z are treated as distinct. 2. Digits All decimal digits from 0 to 9 are allowed. 3. Whitespaces(character or a set of characters that are used for formatting purposes)-to make code easier to read. Eg- Tab-paragraph formatting feature used to align text backspace – ‘b’ horizontal tab- ‘t’ vertical tab – ‘v’ new line- ‘n’ form feed- ‘f’ backslash- ‘’ alert bell- ‘a’ carriage return- ‘r’ question mark- ‘?’ double quotes- ‘”’ is called escape character octal number- ‘000’ hexadecimal no- ‘xhh’ If want to check for any of these whitespaces, use isspace( ) standard library function from ctype.h
  • 20. 4. Special Characters - In association with letters and digits, there are 28 special characters in C , comma . period ; semi colon : colon ’ apostrophe ” quotation marks ! Exclamation marks ~ Tilde < less than > greater than { } braces % percent sign # number sign = equal to @ at the rate + plus sign [ ] brackets ( ) parentheses - minus sign * Asterix ^ caret & ampersand ? Question mark $ dollar _ underscore backslash / slash | vertical bar The characters listed are represented in the computer by numeric values. Each character is assigned a unique numeric value. These values put together are called character codes, which are used in the computer system. The widely used computer codes- ASCII, EBCDIC. ASCII- American Standard Code for Information Interchange. 7 bits – 27 = 128 different characters 8 bits – 28 = 256 different characters A - Z a - z 65 90 97 122
  • 21. Delimiters: (a programming language uses delimiters to mark code , data & instructions boundaries C uses special kind of symbols which are called delimiters. Delimiters Symbols Uses Colon : Useful for labels Semi-colon ; Terminates statements Parenthesis ( ) Used in expressions & statements Square brackets [ ] Used for array & declarations Curly braces { } Scope of statements Hash # Preprocessor directives Comma , Variable separator
  • 22. Types of Tokens: • The smallest unit in a program/statement is called a token. • The compiler views a program in terms of token. • Example: The following C statement consists of five tokens:- printf(“n Hello World”); The individual tokens are- printf- keyword ( - special character “n Hello World” string ) special character ; special character
  • 24. 1. Keywords: • words reserved by the compiler. • 32 keywords by ANSCI standard. 2. Variables: • User-defined words. • Used to store values. • Any number of variables can be defined. 3. Constants: • Words whose values cannot be changed for the entire program run once assigned. 4. Operators: • Used in expressions. 5. Special Characters: • Used in declarations in C. 6. Strings: • A sequence of characters.
  • 25. C Keywords: • are reserved words by the compiler. • Words whose meaning has already been explained to the C compiler. • Have been assigned fixed meanings-cannot change • Cannot be used as variable names. • For utilizing the keywords in a program, no header file is required to be included. • ANSI C provides 32 keywords. • Example: 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. Identifiers:( symbolic names to refer to variable/function/constant) • An identifier is a name used to identify a variable,constant,function, or any other user-defined item.[like structure,union etc] • User-defined names.
  • 26. Rules: • An identifier always starts with a letter A to Z, a to z, or an underscore ‘_’ followed by zero or more letters,underscores, and digits(0-9). • C identifiers does not allow blank spaces, punctuation such as @, $ and %. • C is a case-sensitive language. • Thus, Manpower and manpower are two different identifiers. [ _ is used as a link between two words for the long identifiers] • Valid identifiers: length, area_square, sUm_temp1. • Invalid identifiers: S+um, year’s, length area. • User-defined Identifiers: (i) # define N 10 (ii) # defne a 15
  • 27. printf & scanf in C The printf( ) and scanf( ) functions are used for input and output in C language. Both functions are inbuilt library functions, defined in stdio.h(header file) 1. printf ( ) function: • The printf( ) function is used for output. • It prints the given statement to the console. • The syntax of printf( )- printf(“format string”, argument-list); The format string can be %d(integer) %c(character) %s(string) %f(float) etc 2. scanf( ) function • The scanf( ) function is used for input. • It reads the input data from the console. • The syntax of scanf( )- scanf(“format string”, argument-list); • Example: scanf(“%d”,&number);
  • 28. Program to print cube of a given number: #include<stdio.h> #include<conio.h> void main( ) { int number; clrscr( ); printf(“Enter a number:”); scanf(“%d”,&number); printf(“Cube of number is %d”, number*number*number); getch( ); }
  • 29. Program to print sum of two numbers: #include<stdio.h> #include<conio.h> void main( ) { int x=0,y=0,result=0; clrscr( ); printf( “Enter first number:”); scanf(“%d”, &x); printf(“Enter second number”); scanf(“%d”, &y); result=x+y; printf(“sum of 2 numbers: %d”, result); getch( ); }
  • 30. Data Types: • Variable-named memory location, value keeps varying-not fixed • Every variable has a corresponding data type associated with it. • In C, it is mandatory that every variable has a data type • Why should a variable have a data type? 1. What is the kind of data that will be stored on that location. Eg, int-only numerical values can be stored. 2. How much memory should be allocated for a variable. Eg int-2 bytes, short-2 bytes, long-4 bytes. Eg a/10 –a is alphabet : compiler should give error-will do that on basis of data type of variables. Eg int a=5,int b=2 then a/b will evaluate to 2 not 2.5 because both are integers. Hence, • Expressions are validated based on data type. • Expressions are evaluated based on data type. • Memory is allocated based on data type. • Kind of data that will be stored on that location is done based on data type.
  • 31. Variables: • Named memory location. • So you can refer to the data stored at that location using the name rather than address. In C, variable names must adhere to following rules: 1. The names can contain letters,digits & the underscore character(_). 2. The first character of the name must be a letter. The underscore is also a legal first character , but its use is not recommended. 3. No punctuation marks or blanks are allowed within a variable name. 4. Case matters i.e. upper & lowercase are different. 5. C keywords can’t be used as variable names. Declaring: • A variable definition means to tell the compiler where & how much to create the storage for the variable. • A variable definition specifies a data type & contains a list of one or more variables of that type: Type variable_list; Example: int a,b; • The declaration of the variables should be done in declaration part of the program. • The variables must be declared before they are used in the program. • Declaration ensures two things: 1. Compiler obtains the variables name. 2. It tells to the compiler data types of the variable being declared & helps in allocation of memory.
  • 32. Initializing variables: • Variables declared be assigned or initialized using assignment operator ‘=’. • The declaration & initialization can also be done in the same line. • Syntax: • variable_name =constant; Or • data_type variable_name=constant; • Example: int x=5; int x=y=z=3; int x,y,z; x=y=z=3; Dynamic Initialization: • The initialization of variable at run time is called dynamic initialization[during execution]. • In C, initialization can be done at any place in the program; however the declaration should be done at the declaration part only. • Example: void main() { int r=2; float area=3.14*r*r; //area is calculated & assigned to variable area clrscr( ); printf(“Area= %f”,area); // the expression is solved at run time & assigned to area at run time. }
  • 33. C Data Types Derived Basic User-Defined -Pointer -Structure -Function -Union -Arrays -Enumeration -Typedef Integer Floating point void -char -float -int -double
  • 34. Constants: • Do not change during the execution of the program. Constants Numeric Character Constant Constant -Integer Constant -Character Constant -Real Constant -String Constant 1. Integer Constants: • These are a sequence of numbers from 0 to 9 without decimal points or fractional part or any other symbol. • It requires minimum 2 bytes & maximum 4 bytes. • Integer constant could be either +ve and –ve or maybe zero. • The number without a sign is assumed as positive. • Eg -10,20,+30 etc • Can also be represented in octal & hexadecimal no.s
  • 35. 2. Real Constants: • Often known as floating-point constants. • For representing many quantities, integer constants are not fit. Eg height, distance, weight. • General format: mantissa & exponent. Character Constants: 1. Single Character Constant: • A character constant is a single character. • It can be represented with single digit or a single special symbol or whitespace enclosed within a pair of single quote marks. • Eg ‘8’, ‘a’, ‘-’ • Length of a character, at the most, is one character. • Character constants have integer values known as ASCII values. • For eg, printf(“%c %d”, 65, ‘B’); --- ‘A’ & 66 2. String Constants: • Sequence of characters enclosed within double quote marks. • The string may be a combination of all kinds of symbols. • For eg, “Hello”, “India” , “444”, “a”.
  • 36. Preprocessor Constants: Named constants may also be created using preprocessor. #define SUNDAY 0 .. .. .. int day=SUNDAY; Constant Variable: • If we want the value of a certain variable to remain the same or unchanged during the program execution, it can be done by declaring the variable as a constant. • The keyword const is then prefixed before the declaration. It tells the compiler that the variable is a constant. • Thus, constant declared variable are protected from modification. • Eg const int m=10; Where const is a keyword, m is a variable name & 10 is a constant. • The compiler protects the value of ‘m’ from modification. • The user cannot assign any value to ‘m’.
  • 37. Volatile Variable: • The volatile variables are those variables that can be changed at any time by other external program or the same program. • Eg volatile int d;
  • 38. Type Conversion (promoting lower type to higher type): • Implicit • Explicit void main( ) { printf(“two integer division : %d”, 5/2); printf(“one integer & one float: %f”,5.5/2); printf(“two integers: %f”, (float)5/2); } Third case- Both value are of type int.The result obtained is converted to float. –used type casting (putting data type in a pair of parenthesis before operands. The programmer can specify any data type.
  • 39. i. int x=3.5; --- x will be assigned 3, 0.5 will be lost. ii. int x =35425 – will give unexpected result coz >32768 Invalid: int =long int =float long=float float=double Valid: long=int double=float int=char
  • 40. Type Modifiers: • The keywords signed, unsigned, short & long are type modifiers. • A type modifier changes the meaning of basic data type & produces a new data type. • Each of these type modifiers is applicable to the basic data type int. • The modifiers signed &unsigned are also applicable to the type char. • The long type modifier can be applicable to the double type. • Int(signed) –both +ve and –ve • Unsigned int –restricts to +ve values
  • 41. Format Specifier %c %c %c %d or %i %u %d %u %ld %lu %f %lf %lf Range= -2n-1 to 2 n-1 -1
  • 42. • printf(“%f ”, 1.123456789);--more than 6 • Hence, output will be 1.123457(internally got converted to float, got rounded off & truncated) int a=10.5; printf(“%d”,a);
  • 43. Wrapping Around void main( ) { unsigned int u=65537; clrscr( ); printf(“n u=%u”,u); } Output=1 The unsigned integer u=65537; after reaching the last range 65535, the compiler starts from beginning. Hence, 1 is displayed. The value 65536 refers to 0 & 65537 to 1.