SlideShare a Scribd company logo
Variables, constants,
I/O functions & Header
Files
Variables in C
• A variable is a name of the memory location. It is used to store data. Its value can be
changed, and it can be reused many times.
• It is a way to represent memory location through symbol so that it can be easily identified.
• Syntax: data type variable name;
• The example of declaring the variable is given below:
• int a;
• float b;
• char c
Rules for defining variables
• A variable can have alphabets, digits, and underscore.
• A variable name can start with the alphabet, and underscore only. It can't
start with a digit.
• No whitespace is allowed within the variable name.
• A variable name must not be any reserved word or keyword, e.g. int, float,
etc.
Types of Variables in C
• There following types of variables in c:
• local variable
• global variable
• static variable
Local Variable
• A variable that is declared inside the function or block is called a local
variable.
• It must be declared at the start of the block.
• void function1(){
• int x=10;//local variable
• }
Global Variable
• A variable that is declared outside the function or block is called a global variable.
Any function can change the value of the global variable. It is available to all the
functions.
• It must be declared at the start of the block.
• int value=20;//global variable
• void function1(){
• int x=10;//local variable
• }
Static Variable
• A variable that is declared with the static keyword is called static variable.
• It retains its value between multiple function calls.
• void function1(){
• int x=10;//local variable
• static int y=10;//static variable
• x=x+1;
• y=y+1;
• printf("%d,%d",x,y);
• }
• If you call this function many times, the local variable will print the same value for each function call, e.g, 11,11,11 and
so on. But the static variable will print the incremented value in each function call, e.g. 11, 12, 13 and so on.
Constants in C
• A constant is a value or variable that can't be changed in the program, for example: 10, 20, 'a', 3.4, "c programming" etc.
• There are different types of constants in C programming.
• List of Constants in C
• Constant Example
• Decimal Constant10, 20, 450 etc.
• Real or Floating-point Constant10.3, 20.2, 450.6 etc.
• Octal Constant021, 033, 046 etc.
• Hexadecimal Constant0x2a, 0x7b, 0xaa etc.
• Character Constant‘ a', 'b', 'x' etc.
• String Constant "c", "c program", "c in javatpoint" etc.
What are literals?
• Literals are the constant values assigned to the constant variables. We can say that the literals
represent the fixed values that cannot be modified. It also contains memory but does not have
references as variables. For example, const int =10; is a constant integer expression in which 10 is
an integer literal.
• Types of literals
• There are four types of literals that exist in C programming:
• Integer literal
• Float literal
• Character literal
• String literal
Integer literal
• It is a numeric literal that represents only integer type values. It represents the value neither in fractional nor exponential
part.
• It can be specified in the following three ways:
• Decimal number (base 10)
• It is defined by representing the digits between 0 to 9. For example, 45, 67, etc.
• Octal number (base 8)
• It is defined as a number in which 0 is followed by digits such as 0,1,2,3,4,5,6,7. For example, 012, 034, 055, etc.
• Hexadecimal number (base 16)
• It is defined as a number in which 0x or 0X is followed by the hexadecimal digits (i.e., digits from 0 to 9, alphabetical
characters from (a-f) or (A-f)).
Float literal
• It is a literal that contains only floating-point values or real numbers. These
real numbers contain the number of parts such as integer part, real part,
exponential part, and fractional part. The floating-point literal must be
specified either in decimal or in exponential form. Let's understand these
forms in brief.
Character literal
• A character literal contains a single character enclosed within single quotes. If multiple characters are assigned to the
variable, then we need to create a character array. If we try to store more than one character in a variable, then the warning
of a multi-character character constant will be generated. Let's observe this scenario through an example.
• #include <stdio.h>
• int main()
• {
• const char c='ak';
• printf("%c",c);
• return 0;
• }
String literal
• A string literal represents multiple characters enclosed within double-quotes.
It contains an additional character, i.e., '0' (null character), which gets
automatically inserted. This null character specifies the termination of the
string. We can use the '+' symbol to concatenate two strings.
• For example,
• String1= "javatpoint";
• String2= "family";
C Format Specifier
• The Format specifier is a string used in the formatted input and output
functions. The format string determines the format of the input and output.
The format string always starts with a '%' character.
Formatted and Unformatted I/O functions in
C
• Input means to provide the program with some data to be used in the program and Output meansto display data on screen
or write the data to a printer or a file.
• C programming language provides many built-in functions to read any given input and to display data on screen when there
is a need to output the result.
• C programming language has standard libraries that allow input and output in a program. The stdio.h or standard input
output library in C that has methods for input and output. Input output built-in functions in C falls into two categories,
namely,
• formatted input output (I/O) functions and
• unformatted input output (I/O) functions.
• printf()andscanf()are examples for formatted input and output functions
• and getch(), getche(), getchar(), gets(), puts(), putchar()etc. are examples of unformatted input output functions.
Formatted Input Output Functions
• Formatted input output functions accept or present the data in a particular
format. The standard library consists of different functions that perform
output and input operations.
• Out of these functions, printf() and scanf() allow user to format input
output in desired format.
• printf() and scanf() can be used to read any type of data (integer, real
number, character etc.).
printf() Library Function with Examples
• printf() is formatted output function which is used to display some
information on standard output unit. It is defined in standard header file
stdio.h. So, to use printf(), we must include header file stdio.h in our
program.
• printf() Syntax
• Syntax for printf() is :
• printf("String"); or printf(“format_string”, var1, var2, var3, …, varN);
scanf() Library Function with Examples
• scanf() is formatted input function which is used to read formatted data from
standard input device and automatically converts numeric information to integers
and floats. It is defined in stdio.h.
• scanf() Syntax
• scanf(“format_string”, &var1, &var2, &var3, …, &varN); & in above syntax is
called address operator.
• For Examples :
• int a;
scanf("%d",&a); reads the integer value and stores it to variable a.
Unformatted Input Output Functions
• Unformatted input output functions cannot control the format of reading and
writing the data. These functions are the most basic form of input and output and
they do not allow to supply input or display output in user desired format that's why
we call them unformatted input output functions. Unformatted input output
functions are classified into two categories as character input output functions
and string input output functions.
• Character input functions are used to read a single character from the keyboard and
character output functions are used to write a single character to a screen. getch(),
getche(), and getchar() are unformatted character input functions while putch() and
putchar() are unformatted character output functions.
getch() Library Functions with Examples
• getch() is character input functions. It is unformatted input function meaning
it does not allow user to read input in their format. It reads a character from
the keyboard but does not echo the pressed character and returns character
pressed. It is defined in header file conio.h.
• getch() Syntax
• character_variable = getch(); getch()
getche() Library Functions with Examples
• Like getch(), getche() is also character input functions. It is unformatted
input function meaning it does not allow user to read input in their format.
Difference between getch() and getche() is that getche() echoes pressed
character. getche() also returns character pressed like getch(). It is also
defined in header file conio.h.
• getche() Syntax
• character_variable = getche();
getchar() Library Functions with Examples
• getchar() is also a character input functions. It reads a character and accepts
the input until carriage return is entered (i.e. until enter is pressed). It is
defined in header file stdio.h.
• getchar() Syntax
• character_variable = getchar();
putch() Library Function with Examples
• The putch() function is used for printing character to a screen at current
cursor location. It is unformatted character output functions. It is defined in
header file conio.h.
• putch() Syntax
• putch(character); or putch(character_variable);
putchar() Library Function with Examples
• The putchar() function is used for printing character to a screen at current
cursor location. It is unformatted character output functions. It is defined in
header file stdio.h.
• putchar() Syntax
• putchar(character); or putchar(character_variable);
gets() Library Functions with Examples
• gets() is string input functions. It reads string from the keyboard. It reads
string until enter is pressed. It is defined in header file stdio.h.
• gets() Syntax
• gets(string_variable);
puts() Library Function with Examples
• puts() is unformatted string output functions. It writes or prints string to
screen. It is defined in standard header file stdio.h.
• puts() Syntax
• puts(string or string_variable);
• https://www.codesansar.com/c-programming/input-and-output-
functions.htm
Expression
• Expression: An expression is a combination of operators, constants and
variables. An expression may consist of one or more operands, and zero or
more operators to produce a value
• e.
• Constant expressions: Constant Expressions consists of only constant values. A
constant value is one that doesn’t change.
Examples: 5, 10 + 5 / 6.0, 'x’ Integral expressions: Integral Expressions are
those which produce integer results after implementing all the automatic and explicit
type conversions.
Examples: x, x * y, x + int( 5.0) where x and y are integer variables.
• Floating expressions: Float Expressions are which produce floating point results
after implementing all the automatic and explicit type conversions.
Examples: x + y, 10.75 where x and y are floating point variables.
• Relational expressions: Relational Expressions yield results of type bool which
takes a value true or false. When arithmetic expressions are used on either side of a
relational operator, they will be evaluated first and then the results compared.
Relational expressions are also known as Boolean expressions.
Examples: x <= y, x + y > 2
• Logical expressions: Logical Expressions combine two or more relational
expressions and produces bool type results.
Examples: x > y && x == 10, x == 10 || y == 5
What is Typecasting in C?
• Typecasting is converting one data type into another one. It is also called as
data conversion or type conversion. It is one of the important concepts
introduced in 'C' programming.
• 'C' programming provides two types of type casting operations:
• Implicit type casting
• Explicit type casting
IMPLICIT TYPE CONVERSION
• Implicit type conversion is performed automatic by compiler without
program interference. Type conversion takes place to avoid lose of data.
EXPLICIT TYPE CONVERSION
• In explicit type conversion, C allows the programmer to create a variable and
to change its type by using the type cast operator and process is called type
casting.
HEADER FILES
• In C language, header files contain the set of predefined standard library
functions. The “#include” preprocessing directive is used to include the
header files with “.h” extension in the program.
• Here is the table that displays some of the header files in C language,
C language

More Related Content

What's hot

12 computer science_notes_ch01_overview_of_cpp
12 computer science_notes_ch01_overview_of_cpp12 computer science_notes_ch01_overview_of_cpp
12 computer science_notes_ch01_overview_of_cpp
sharvivek
 
C programming_MSBTE_Diploma_Pranoti Doke
C programming_MSBTE_Diploma_Pranoti DokeC programming_MSBTE_Diploma_Pranoti Doke
C programming_MSBTE_Diploma_Pranoti Doke
Pranoti Doke
 
Introduction to Basic C programming 01
Introduction to Basic C programming 01Introduction to Basic C programming 01
Introduction to Basic C programming 01
Wingston
 
What is c
What is cWhat is c
What is c
Nitesh Saitwal
 
Unit ii ppt
Unit ii pptUnit ii ppt
2nd PUC Computer science chapter 5 review of c++
2nd PUC Computer science chapter 5   review of c++2nd PUC Computer science chapter 5   review of c++
2nd PUC Computer science chapter 5 review of c++
Aahwini Esware gowda
 
Tutorial on c language programming
Tutorial on c language programmingTutorial on c language programming
Tutorial on c language programming
Sudheer Kiran
 
Chapter 2: Elementary Programming
Chapter 2: Elementary ProgrammingChapter 2: Elementary Programming
Chapter 2: Elementary Programming
Eric Chou
 
Getting started with c++
Getting started with c++Getting started with c++
Getting started with c++
K Durga Prasad
 
Getting Started with C++
Getting Started with C++Getting Started with C++
Getting Started with C++
Praveen M Jigajinni
 
C programming tutorial for Beginner
C programming tutorial for BeginnerC programming tutorial for Beginner
C programming tutorial for Beginner
sophoeutsen2
 
Managing input and output operation in c
Managing input and output operation in cManaging input and output operation in c
Managing input and output operation in c
yazad dumasia
 
Constants Variables Datatypes by Mrs. Sowmya Jyothi
Constants Variables Datatypes by Mrs. Sowmya JyothiConstants Variables Datatypes by Mrs. Sowmya Jyothi
Constants Variables Datatypes by Mrs. Sowmya Jyothi
SowmyaJyothi3
 
OpenGurukul : Language : C Programming
OpenGurukul : Language : C ProgrammingOpenGurukul : Language : C Programming
OpenGurukul : Language : C Programming
Open Gurukul
 
Intro to C++ - language
Intro to C++ - languageIntro to C++ - language
Intro to C++ - language
Jussi Pohjolainen
 
Data type in c
Data type in cData type in c
Data type in c
thirumalaikumar3
 
C programming language
C programming languageC programming language
C programming language
Mahmoud Eladawi
 
358 33 powerpoint-slides_1-introduction-c_chapter-1
358 33 powerpoint-slides_1-introduction-c_chapter-1358 33 powerpoint-slides_1-introduction-c_chapter-1
358 33 powerpoint-slides_1-introduction-c_chapter-1
sumitbardhan
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
javaTpoint s
 
C Token’s
C Token’sC Token’s
C Token’s
Tarun Sharma
 

What's hot (20)

12 computer science_notes_ch01_overview_of_cpp
12 computer science_notes_ch01_overview_of_cpp12 computer science_notes_ch01_overview_of_cpp
12 computer science_notes_ch01_overview_of_cpp
 
C programming_MSBTE_Diploma_Pranoti Doke
C programming_MSBTE_Diploma_Pranoti DokeC programming_MSBTE_Diploma_Pranoti Doke
C programming_MSBTE_Diploma_Pranoti Doke
 
Introduction to Basic C programming 01
Introduction to Basic C programming 01Introduction to Basic C programming 01
Introduction to Basic C programming 01
 
What is c
What is cWhat is c
What is c
 
Unit ii ppt
Unit ii pptUnit ii ppt
Unit ii ppt
 
2nd PUC Computer science chapter 5 review of c++
2nd PUC Computer science chapter 5   review of c++2nd PUC Computer science chapter 5   review of c++
2nd PUC Computer science chapter 5 review of c++
 
Tutorial on c language programming
Tutorial on c language programmingTutorial on c language programming
Tutorial on c language programming
 
Chapter 2: Elementary Programming
Chapter 2: Elementary ProgrammingChapter 2: Elementary Programming
Chapter 2: Elementary Programming
 
Getting started with c++
Getting started with c++Getting started with c++
Getting started with c++
 
Getting Started with C++
Getting Started with C++Getting Started with C++
Getting Started with C++
 
C programming tutorial for Beginner
C programming tutorial for BeginnerC programming tutorial for Beginner
C programming tutorial for Beginner
 
Managing input and output operation in c
Managing input and output operation in cManaging input and output operation in c
Managing input and output operation in c
 
Constants Variables Datatypes by Mrs. Sowmya Jyothi
Constants Variables Datatypes by Mrs. Sowmya JyothiConstants Variables Datatypes by Mrs. Sowmya Jyothi
Constants Variables Datatypes by Mrs. Sowmya Jyothi
 
OpenGurukul : Language : C Programming
OpenGurukul : Language : C ProgrammingOpenGurukul : Language : C Programming
OpenGurukul : Language : C Programming
 
Intro to C++ - language
Intro to C++ - languageIntro to C++ - language
Intro to C++ - language
 
Data type in c
Data type in cData type in c
Data type in c
 
C programming language
C programming languageC programming language
C programming language
 
358 33 powerpoint-slides_1-introduction-c_chapter-1
358 33 powerpoint-slides_1-introduction-c_chapter-1358 33 powerpoint-slides_1-introduction-c_chapter-1
358 33 powerpoint-slides_1-introduction-c_chapter-1
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
 
C Token’s
C Token’sC Token’s
C Token’s
 

Similar to C language

Esoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingEsoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programming
Rasan Samarasinghe
 
C
CC
Console I/o & basics of array and strings.pptx
Console I/o & basics of array and strings.pptxConsole I/o & basics of array and strings.pptx
Console I/o & basics of array and strings.pptx
PRASENJITMORE2
 
MCA 101-Programming in C with Data Structure UNIT I by Prof. Rohit Dubey
MCA 101-Programming in C with Data Structure UNIT I by Prof. Rohit DubeyMCA 101-Programming in C with Data Structure UNIT I by Prof. Rohit Dubey
MCA 101-Programming in C with Data Structure UNIT I by Prof. Rohit Dubey
kiranrajat
 
Fundamentals of Programming Constructs.pptx
Fundamentals of  Programming Constructs.pptxFundamentals of  Programming Constructs.pptx
Fundamentals of Programming Constructs.pptx
vijayapraba1
 
Functions IN CPROGRAMMING OF ENGINEERING.pptx
Functions IN CPROGRAMMING OF ENGINEERING.pptxFunctions IN CPROGRAMMING OF ENGINEERING.pptx
Functions IN CPROGRAMMING OF ENGINEERING.pptx
vanshhans21102005
 
Unit 4 Foc
Unit 4 FocUnit 4 Foc
Unit 4 Foc
JAYA
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
MOHAMAD NOH AHMAD
 
C PROGRAMING.pptx
C PROGRAMING.pptxC PROGRAMING.pptx
C PROGRAMING.pptx
MohammedtajuddinTaju
 
C_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptxC_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptx
Likhil181
 
2. introduction of a c program
2. introduction of a c program2. introduction of a c program
2. introduction of a c program
Alamgir Hossain
 
M.Florence Dayana / Basics of C Language
M.Florence Dayana / Basics of C LanguageM.Florence Dayana / Basics of C Language
M.Florence Dayana / Basics of C Language
Dr.Florence Dayana
 
Cpu
CpuCpu
C programming language
C programming languageC programming language
C programming language
Abin Rimal
 
C programming language tutorial
C programming language tutorialC programming language tutorial
C programming language tutorial
SURBHI SAROHA
 
Lec-1c.pdf
Lec-1c.pdfLec-1c.pdf
Lec-1c.pdf
Ritikchaudhary72
 
C language
C languageC language
C language
Mukul Kirti Verma
 
Chap 1 and 2
Chap 1 and 2Chap 1 and 2
INTRODUCTION TO C++.pptx
INTRODUCTION TO C++.pptxINTRODUCTION TO C++.pptx
INTRODUCTION TO C++.pptx
MamataAnilgod
 
A brief introduction to C Language
A brief introduction to C LanguageA brief introduction to C Language
A brief introduction to C Language
Mohamed Elsayed
 

Similar to C language (20)

Esoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingEsoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programming
 
C
CC
C
 
Console I/o & basics of array and strings.pptx
Console I/o & basics of array and strings.pptxConsole I/o & basics of array and strings.pptx
Console I/o & basics of array and strings.pptx
 
MCA 101-Programming in C with Data Structure UNIT I by Prof. Rohit Dubey
MCA 101-Programming in C with Data Structure UNIT I by Prof. Rohit DubeyMCA 101-Programming in C with Data Structure UNIT I by Prof. Rohit Dubey
MCA 101-Programming in C with Data Structure UNIT I by Prof. Rohit Dubey
 
Fundamentals of Programming Constructs.pptx
Fundamentals of  Programming Constructs.pptxFundamentals of  Programming Constructs.pptx
Fundamentals of Programming Constructs.pptx
 
Functions IN CPROGRAMMING OF ENGINEERING.pptx
Functions IN CPROGRAMMING OF ENGINEERING.pptxFunctions IN CPROGRAMMING OF ENGINEERING.pptx
Functions IN CPROGRAMMING OF ENGINEERING.pptx
 
Unit 4 Foc
Unit 4 FocUnit 4 Foc
Unit 4 Foc
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
C PROGRAMING.pptx
C PROGRAMING.pptxC PROGRAMING.pptx
C PROGRAMING.pptx
 
C_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptxC_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptx
 
2. introduction of a c program
2. introduction of a c program2. introduction of a c program
2. introduction of a c program
 
M.Florence Dayana / Basics of C Language
M.Florence Dayana / Basics of C LanguageM.Florence Dayana / Basics of C Language
M.Florence Dayana / Basics of C Language
 
Cpu
CpuCpu
Cpu
 
C programming language
C programming languageC programming language
C programming language
 
C programming language tutorial
C programming language tutorialC programming language tutorial
C programming language tutorial
 
Lec-1c.pdf
Lec-1c.pdfLec-1c.pdf
Lec-1c.pdf
 
C language
C languageC language
C language
 
Chap 1 and 2
Chap 1 and 2Chap 1 and 2
Chap 1 and 2
 
INTRODUCTION TO C++.pptx
INTRODUCTION TO C++.pptxINTRODUCTION TO C++.pptx
INTRODUCTION TO C++.pptx
 
A brief introduction to C Language
A brief introduction to C LanguageA brief introduction to C Language
A brief introduction to C Language
 

Recently uploaded

writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
ak6969907
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
adhitya5119
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
RitikBhardwaj56
 
Assessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptxAssessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptx
Kavitha Krishnan
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Smart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICTSmart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICT
simonomuemu
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
National Information Standards Organization (NISO)
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
taiba qazi
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
Celine George
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 

Recently uploaded (20)

writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
 
Assessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptxAssessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptx
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Smart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICTSmart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICT
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 

C language

  • 2. Variables in C • A variable is a name of the memory location. It is used to store data. Its value can be changed, and it can be reused many times. • It is a way to represent memory location through symbol so that it can be easily identified. • Syntax: data type variable name; • The example of declaring the variable is given below: • int a; • float b; • char c
  • 3. Rules for defining variables • A variable can have alphabets, digits, and underscore. • A variable name can start with the alphabet, and underscore only. It can't start with a digit. • No whitespace is allowed within the variable name. • A variable name must not be any reserved word or keyword, e.g. int, float, etc.
  • 4. Types of Variables in C • There following types of variables in c: • local variable • global variable • static variable
  • 5. Local Variable • A variable that is declared inside the function or block is called a local variable. • It must be declared at the start of the block. • void function1(){ • int x=10;//local variable • }
  • 6. Global Variable • A variable that is declared outside the function or block is called a global variable. Any function can change the value of the global variable. It is available to all the functions. • It must be declared at the start of the block. • int value=20;//global variable • void function1(){ • int x=10;//local variable • }
  • 7. Static Variable • A variable that is declared with the static keyword is called static variable. • It retains its value between multiple function calls. • void function1(){ • int x=10;//local variable • static int y=10;//static variable • x=x+1; • y=y+1; • printf("%d,%d",x,y); • } • If you call this function many times, the local variable will print the same value for each function call, e.g, 11,11,11 and so on. But the static variable will print the incremented value in each function call, e.g. 11, 12, 13 and so on.
  • 8. Constants in C • A constant is a value or variable that can't be changed in the program, for example: 10, 20, 'a', 3.4, "c programming" etc. • There are different types of constants in C programming. • List of Constants in C • Constant Example • Decimal Constant10, 20, 450 etc. • Real or Floating-point Constant10.3, 20.2, 450.6 etc. • Octal Constant021, 033, 046 etc. • Hexadecimal Constant0x2a, 0x7b, 0xaa etc. • Character Constant‘ a', 'b', 'x' etc. • String Constant "c", "c program", "c in javatpoint" etc.
  • 9. What are literals? • Literals are the constant values assigned to the constant variables. We can say that the literals represent the fixed values that cannot be modified. It also contains memory but does not have references as variables. For example, const int =10; is a constant integer expression in which 10 is an integer literal. • Types of literals • There are four types of literals that exist in C programming: • Integer literal • Float literal • Character literal • String literal
  • 10. Integer literal • It is a numeric literal that represents only integer type values. It represents the value neither in fractional nor exponential part. • It can be specified in the following three ways: • Decimal number (base 10) • It is defined by representing the digits between 0 to 9. For example, 45, 67, etc. • Octal number (base 8) • It is defined as a number in which 0 is followed by digits such as 0,1,2,3,4,5,6,7. For example, 012, 034, 055, etc. • Hexadecimal number (base 16) • It is defined as a number in which 0x or 0X is followed by the hexadecimal digits (i.e., digits from 0 to 9, alphabetical characters from (a-f) or (A-f)).
  • 11. Float literal • It is a literal that contains only floating-point values or real numbers. These real numbers contain the number of parts such as integer part, real part, exponential part, and fractional part. The floating-point literal must be specified either in decimal or in exponential form. Let's understand these forms in brief.
  • 12. Character literal • A character literal contains a single character enclosed within single quotes. If multiple characters are assigned to the variable, then we need to create a character array. If we try to store more than one character in a variable, then the warning of a multi-character character constant will be generated. Let's observe this scenario through an example. • #include <stdio.h> • int main() • { • const char c='ak'; • printf("%c",c); • return 0; • }
  • 13. String literal • A string literal represents multiple characters enclosed within double-quotes. It contains an additional character, i.e., '0' (null character), which gets automatically inserted. This null character specifies the termination of the string. We can use the '+' symbol to concatenate two strings. • For example, • String1= "javatpoint"; • String2= "family";
  • 14. C Format Specifier • The Format specifier is a string used in the formatted input and output functions. The format string determines the format of the input and output. The format string always starts with a '%' character.
  • 15.
  • 16. Formatted and Unformatted I/O functions in C • Input means to provide the program with some data to be used in the program and Output meansto display data on screen or write the data to a printer or a file. • C programming language provides many built-in functions to read any given input and to display data on screen when there is a need to output the result. • C programming language has standard libraries that allow input and output in a program. The stdio.h or standard input output library in C that has methods for input and output. Input output built-in functions in C falls into two categories, namely, • formatted input output (I/O) functions and • unformatted input output (I/O) functions. • printf()andscanf()are examples for formatted input and output functions • and getch(), getche(), getchar(), gets(), puts(), putchar()etc. are examples of unformatted input output functions.
  • 17. Formatted Input Output Functions • Formatted input output functions accept or present the data in a particular format. The standard library consists of different functions that perform output and input operations. • Out of these functions, printf() and scanf() allow user to format input output in desired format. • printf() and scanf() can be used to read any type of data (integer, real number, character etc.).
  • 18. printf() Library Function with Examples • printf() is formatted output function which is used to display some information on standard output unit. It is defined in standard header file stdio.h. So, to use printf(), we must include header file stdio.h in our program. • printf() Syntax • Syntax for printf() is : • printf("String"); or printf(“format_string”, var1, var2, var3, …, varN);
  • 19. scanf() Library Function with Examples • scanf() is formatted input function which is used to read formatted data from standard input device and automatically converts numeric information to integers and floats. It is defined in stdio.h. • scanf() Syntax • scanf(“format_string”, &var1, &var2, &var3, …, &varN); & in above syntax is called address operator. • For Examples : • int a; scanf("%d",&a); reads the integer value and stores it to variable a.
  • 20. Unformatted Input Output Functions • Unformatted input output functions cannot control the format of reading and writing the data. These functions are the most basic form of input and output and they do not allow to supply input or display output in user desired format that's why we call them unformatted input output functions. Unformatted input output functions are classified into two categories as character input output functions and string input output functions. • Character input functions are used to read a single character from the keyboard and character output functions are used to write a single character to a screen. getch(), getche(), and getchar() are unformatted character input functions while putch() and putchar() are unformatted character output functions.
  • 21. getch() Library Functions with Examples • getch() is character input functions. It is unformatted input function meaning it does not allow user to read input in their format. It reads a character from the keyboard but does not echo the pressed character and returns character pressed. It is defined in header file conio.h. • getch() Syntax • character_variable = getch(); getch()
  • 22. getche() Library Functions with Examples • Like getch(), getche() is also character input functions. It is unformatted input function meaning it does not allow user to read input in their format. Difference between getch() and getche() is that getche() echoes pressed character. getche() also returns character pressed like getch(). It is also defined in header file conio.h. • getche() Syntax • character_variable = getche();
  • 23. getchar() Library Functions with Examples • getchar() is also a character input functions. It reads a character and accepts the input until carriage return is entered (i.e. until enter is pressed). It is defined in header file stdio.h. • getchar() Syntax • character_variable = getchar();
  • 24. putch() Library Function with Examples • The putch() function is used for printing character to a screen at current cursor location. It is unformatted character output functions. It is defined in header file conio.h. • putch() Syntax • putch(character); or putch(character_variable);
  • 25. putchar() Library Function with Examples • The putchar() function is used for printing character to a screen at current cursor location. It is unformatted character output functions. It is defined in header file stdio.h. • putchar() Syntax • putchar(character); or putchar(character_variable);
  • 26. gets() Library Functions with Examples • gets() is string input functions. It reads string from the keyboard. It reads string until enter is pressed. It is defined in header file stdio.h. • gets() Syntax • gets(string_variable);
  • 27. puts() Library Function with Examples • puts() is unformatted string output functions. It writes or prints string to screen. It is defined in standard header file stdio.h. • puts() Syntax • puts(string or string_variable);
  • 29. Expression • Expression: An expression is a combination of operators, constants and variables. An expression may consist of one or more operands, and zero or more operators to produce a value • e.
  • 30.
  • 31.
  • 32. • Constant expressions: Constant Expressions consists of only constant values. A constant value is one that doesn’t change. Examples: 5, 10 + 5 / 6.0, 'x’ Integral expressions: Integral Expressions are those which produce integer results after implementing all the automatic and explicit type conversions. Examples: x, x * y, x + int( 5.0) where x and y are integer variables. • Floating expressions: Float Expressions are which produce floating point results after implementing all the automatic and explicit type conversions. Examples: x + y, 10.75 where x and y are floating point variables. • Relational expressions: Relational Expressions yield results of type bool which takes a value true or false. When arithmetic expressions are used on either side of a relational operator, they will be evaluated first and then the results compared. Relational expressions are also known as Boolean expressions. Examples: x <= y, x + y > 2 • Logical expressions: Logical Expressions combine two or more relational expressions and produces bool type results. Examples: x > y && x == 10, x == 10 || y == 5
  • 33. What is Typecasting in C? • Typecasting is converting one data type into another one. It is also called as data conversion or type conversion. It is one of the important concepts introduced in 'C' programming. • 'C' programming provides two types of type casting operations: • Implicit type casting • Explicit type casting
  • 34. IMPLICIT TYPE CONVERSION • Implicit type conversion is performed automatic by compiler without program interference. Type conversion takes place to avoid lose of data.
  • 35. EXPLICIT TYPE CONVERSION • In explicit type conversion, C allows the programmer to create a variable and to change its type by using the type cast operator and process is called type casting.
  • 36. HEADER FILES • In C language, header files contain the set of predefined standard library functions. The “#include” preprocessing directive is used to include the header files with “.h” extension in the program. • Here is the table that displays some of the header files in C language,