SlideShare uma empresa Scribd logo
1 de 37
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

Mais conteúdo relacionado

Mais procurados

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_cppsharvivek
 
C programming_MSBTE_Diploma_Pranoti Doke
C programming_MSBTE_Diploma_Pranoti DokeC programming_MSBTE_Diploma_Pranoti Doke
C programming_MSBTE_Diploma_Pranoti DokePranoti Doke
 
Introduction to Basic C programming 01
Introduction to Basic C programming 01Introduction to Basic C programming 01
Introduction to Basic C programming 01Wingston
 
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 programmingSudheer Kiran
 
Chapter 2: Elementary Programming
Chapter 2: Elementary ProgrammingChapter 2: Elementary Programming
Chapter 2: Elementary ProgrammingEric Chou
 
Getting started with c++
Getting started with c++Getting started with c++
Getting started with c++K Durga Prasad
 
C programming tutorial for Beginner
C programming tutorial for BeginnerC programming tutorial for Beginner
C programming tutorial for Beginnersophoeutsen2
 
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 cyazad 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 JyothiSowmyaJyothi3
 
OpenGurukul : Language : C Programming
OpenGurukul : Language : C ProgrammingOpenGurukul : Language : C Programming
OpenGurukul : Language : C ProgrammingOpen Gurukul
 
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-1sumitbardhan
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial javaTpoint s
 

Mais procurados (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
 

Semelhante a 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++ programmingRasan Samarasinghe
 
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.pptxPRASENJITMORE2
 
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 Dubeykiranrajat
 
Fundamentals of Programming Constructs.pptx
Fundamentals of  Programming Constructs.pptxFundamentals of  Programming Constructs.pptx
Fundamentals of Programming Constructs.pptxvijayapraba1
 
Functions IN CPROGRAMMING OF ENGINEERING.pptx
Functions IN CPROGRAMMING OF ENGINEERING.pptxFunctions IN CPROGRAMMING OF ENGINEERING.pptx
Functions IN CPROGRAMMING OF ENGINEERING.pptxvanshhans21102005
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C ProgrammingMOHAMAD NOH AHMAD
 
Unit 4 Foc
Unit 4 FocUnit 4 Foc
Unit 4 FocJAYA
 
C_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptxC_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptxLikhil181
 
2. introduction of a c program
2. introduction of a c program2. introduction of a c program
2. introduction of a c programAlamgir 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 LanguageDr.Florence Dayana
 
C programming language
C programming languageC programming language
C programming languageAbin Rimal
 
C programming language tutorial
C programming language tutorialC programming language tutorial
C programming language tutorialSURBHI SAROHA
 
INTRODUCTION TO C++.pptx
INTRODUCTION TO C++.pptxINTRODUCTION TO C++.pptx
INTRODUCTION TO C++.pptxMamataAnilgod
 
A brief introduction to C Language
A brief introduction to C LanguageA brief introduction to C Language
A brief introduction to C LanguageMohamed Elsayed
 

Semelhante a 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
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
Unit 4 Foc
Unit 4 FocUnit 4 Foc
Unit 4 Foc
 
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
 

Último

Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 

Último (20)

Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 

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,