SlideShare a Scribd company logo
1 of 14
Download to read offline
1. Discuss the basic data types in C.
C language is rich in data types. Data types refer to an
extensive system used for declaring variables or functions of
different types. The type of a variable determines how much
space it occupies in storage and how the bit pattern stored is
interpreted.
There are 4 classes of data types:
1. Primary data types (int, float, char)
2. User defined data types (enumerator, typedef)
3. Derived data types (array, function, pointers, structure,
union)
4. Empty data sets. (void)
2.What is a statement in C? Discuss the different types of
statements in C, giving suitable examples of each.
A statement is a command given to the computer that instructs
the computer to take a specific action, such as display to the
screen, or collect input. A computer program is made up of a
series of statements.
Labeled Statements
A statement can be preceded by a label. Three types of labels
exist in C.
A simple identifier followed by a colon (:) is a label. Usually, this
label is the target of a goto statement.
Within switch statements, case and default labeled
statements exist.
A statement of the form
case constant-expression : statement
Compound Statements
A compound statement is the way C groups multiple
statements into a single statement. It consists of multiple
statements and declarations within braces (i.e. { and }). The
body of a function is also a compound statement by rule.
Expression Statements
An expression statement consists of an optional expression
followed by a semicolon (;). If the expression is present, the
statement may have a value. If no expression is present, the
statement is often called the null statement.
The printf function calls are expressions, so statements such as
printf ("Hello World!n"); are expression statements.
Selection Statements
Three types of selection statements exist in C:
if ( expression ) statement
In this type of if-statement, the sub-statement will only be
executed iff the expression is non-zero.
if ( expression ) statement else statement
Iteration Statements
C has three kinds of iteration statements. The first is a while-
statement with the form
while ( expression ) statement
The substatement of a while runs repeatedly as long as the
control expression evaluates to non-zero at the beginning of each
iteration. If the control expression evaluates to zero the first time
through, the substatement may not run at all.
The second is a do-while statement of the form
do statement while ( expression ) ;
This is similar to a while loop, except that the controlling
expression is evaluated at the end of the loop instead of the
beginning and consequently the sub-statement must execute at
least once.
The third type of iteration statement is the for-statement. In ANSI
C 1989, it has the form
for ( expressionopt ; expressionopt ; expressionopt ) statement
In more recent versions of the C standard, a declaration can
substitute for the first expression. The opt subscript indicates that
the expression is optional.
Jump Statements
C has four types of jump statements. The first, the goto
statement, is used sparingly and has the form
goto identifier ;
This statement transfers control flow to the statement labeled with
the given identifier. The statement must be within the same
function as the goto.
The second, the break statement, with the form
break ;
is used within iteration statements and switch statements to pass
control flow to the statement following the while, do-while, for, or
switch.
The third, the continue statement, with the form
continue ;
is used within the substatement of iteration statements to transfer
control flow to the place just before the end of the substatement.
In for statements the iteration expression (e3 above) will then be
executed before the controlling expression (e2 above) is
evaluated.
The fourth type of jump statement is the return statement with the
form
return expressionopt ;
This statement returns from the function. If the function return
type is void, the function may not return a value; otherwise, the
expression represents the value to be returned.
3. What is the role of the pre-processor in C? Explain the use
of pre-processor directives like #include and #define with
suitable examples.
he C preprocessor is the macro preprocessor for the C, Objective-
C and C++ computer programming languages. The preprocessor
provides the ability for the inclusion of header files, macro
expansions, conditional compilation, and line control.
In many C implementations, it is a separate program invoked by
the compiler as the first part of translation.
The language of preprocessor directives is only weakly related to
the grammar of C, and so is sometimes used to process other
kinds of text files.
1. #define (Macros)
A macro is a code that is replaced by some value of the code of
macro. Any macro is mostly described and defined by its #define
directive.
Syntax:
#define token value
There are two types of macros:
Function – like macros
Object – like macros
Function – like macros
The function like-macro works almost like a function call.
For example:
#define MAX(a,b) ((a)>(b) ? (a): (b))
For example:
#define MAX(a,b) ((a)>(b) ? (a): (b))
MAX here is the Macro name
2 #include
There is some other functionality for the include preprocessor
directive. It has its own three variants which replace the code with
the current source files code.
Three variants are as follows:
#include<file>
#include”file”
Include anything else
#include<file>
Searches for a file in the defined list of the system or directories
as specified then searches for a standard list of system libraries.
#include”file”
This type is used for your own customized header files of the
program. A search is made for a file named file first in the current
directory followed by system header files and current directories
of directory current file.
#include anything
4. Describe the ASCII Character Set, and discuss it’s
importance in modern computing systems
All the character sets used in the C language have their
equivalent ASCII value. The ASCII value stands for American
Standard Code for Information Interchange value. It consists of
less than 256 characters, and we can represent these in 8 bits or
even less. But we use a special type for accommodating and
representing the larger sets of characters. These are called the
wide-character type or wchat_t.
However, a majority of the ANSI-compatible compilers in C accept
these ASCII characters for both the character sets- the source
and the execution. Every ASCII character will correspond to a
specific numeric value.
The character sets help in defining the valid characters that we
can use in the source program or can interpret during the running
of the program. For the source text, we have the source character
set, while we have the execution character set that we use during
the execution of any program.
But we have various types of character sets. For instance, one of
the character sets follows the basis of the ASCII character
definitions, while the other set consists of various kanji characters
(Japanese).
The type of character set we use will have no impact on the
compiler- but we must know that every character has different,
unique values. The C language treats every character with
different integer values.
5. Write a C program to calculate and display the volume (V)
and area (A) of a sphere using the formulae: Area A = 4*PI*R2
and Volume = AR/3, where R is the radius.
/*
* C Program to Find Volume and Area of Sphere
*/
#include <stdio.h>
#include <math.h>
#define PI 3.14
int main()
{
float R;
float A, volume;
printf("Enter radius of the sphere : n");
scanf("%f", &R);
A = 4 * PI * R * R;
volume = A * R * 1/3;
printf("area of sphere is: %f", A);
printf("n Volume of sphere is : %f", volume);
return 0;
}
6. Write a program to read your name, roll number and CGPA
and displays them to the screen.
#include <stdio.h>
struct student {
char name[50];
int roll;
float CGPA;
} s;
int main() {
printf("Enter information:n");
printf("Enter name: ");
fgets(s.name, sizeof(s.name), stdin);
printf("Enter roll number: ");
scanf("%d", &s.roll);
printf("Enter CGPA: ");
scanf("%f", &s.CGPA);
printf("Displaying Information:n");
printf("Name: ");
printf("%s", s.name);
printf("Roll number: %dn", s.roll);
printf("CGPA : %.1fn", s.CGPA);
return 0;
}
7. Write a C program that accepts a real number and prints
the integral and fractional parts on the screen.
#include <stdio.h>
int main()
{
float num;
printf("enter a number :") ;
scanf("%f",&num);
int num_integer = (int)num;
float num_decimal = num - num_integer;
printf("integer part: %d , fractional part : %fn",num_integer ,
num_decimal);
return 0 ;
}
8. Write a C program to convert a temperature reading in
degrees Fahrenheit to degrees Celsius, using the formula: C
= (5/9)x(F-32).
#include<stdio.h>
int main()
{ float F, Celsius;
printf("Enter a temp in F: ");
scanf("%f", &F);
Celsius = ((F-32)*5)/9;
printf("nn Temperature in Celsius is : %f",Celsius);
return (0);
}
9. What is meant by operator precedence and associativity?
Build a table showing the associativity and relative
precedence of various types of operators supported in C.
Operator precedence determines the grouping of terms in an
expression and decides how an expression is evaluated. Certain
operators have higher precedence than others; for example, the
multiplication operator has a higher precedence than the addition
operator.
Operators Associativity is used when two operators of same
precedence appear in an expression. Associativity can be either
Left to Right or Right to Left
.
10. What is a unary operator? Discuss the purpose of any
two unary operators supported by the C language. Also
explain with a suitable code sample, the use of the
conditional operator (?:).
These are the type of operators that act upon just a single
operand for producing a new value. All the unary operators have
equal precedence, and their associativity is from right to left.
When we combine the unary operator with an operand, we get the
unary expression.
Types of Unary Operator in C
There are following types of unary operators found in the C
language:
unary minus (-)
unary plus (+)
decrement (- -)
increment (++)
NOT (!)
sizeof ()
Address of operator (&)
Unary Minus
This operator changes the sign of any given argument. It means
that a positive number will become negative, and a negative
number will become positive.
But the unary minus is different from that of the subtractor
operator. It is because we require two operands for subtraction.
int p = 20;
int q = -p; // q = -20
Unary Plus
This operator changes the sign of any negative argument. It
means that a negative number will become positive, and a
positive number will also become positive.
But the unary minus is different from that of the subtractor
operator. It is because we require two operands for subtraction.
int p = -20;
int q = +p; // q = 20

More Related Content

Similar to C Data Types and Variables

C Language (All Concept)
C Language (All Concept)C Language (All Concept)
C Language (All Concept)sachindane
 
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptxIIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptxrajkumar490591
 
Problem Solving Techniques
Problem Solving TechniquesProblem Solving Techniques
Problem Solving Techniquesvalarpink
 
C programming notes.pdf
C programming notes.pdfC programming notes.pdf
C programming notes.pdfAdiseshaK
 
Interview Questions For C Language
Interview Questions For C Language Interview Questions For C Language
Interview Questions For C Language Rowank2
 
Interview Questions For C Language .pptx
Interview Questions For C Language .pptxInterview Questions For C Language .pptx
Interview Questions For C Language .pptxRowank2
 
1. introduction to computer
1. introduction to computer1. introduction to computer
1. introduction to computerShankar Gangaju
 
1584503386 1st chap
1584503386 1st chap1584503386 1st chap
1584503386 1st chapthuhiendtk4
 
C programming Training in Ambala ! Batra Computer Centre
C programming Training in Ambala ! Batra Computer CentreC programming Training in Ambala ! Batra Computer Centre
C programming Training in Ambala ! Batra Computer Centrejatin batra
 
Introduction to Computer and Programming - Lecture 03
Introduction to Computer and Programming - Lecture 03Introduction to Computer and Programming - Lecture 03
Introduction to Computer and Programming - Lecture 03hassaanciit
 
C programming course material
C programming course materialC programming course material
C programming course materialRanjitha Murthy
 
C_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptxC_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptxLikhil181
 
Introduction to C Unit 1
Introduction to C Unit 1Introduction to C Unit 1
Introduction to C Unit 1SURBHI SAROHA
 

Similar to C Data Types and Variables (20)

C Language (All Concept)
C Language (All Concept)C Language (All Concept)
C Language (All Concept)
 
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptxIIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
 
Problem Solving Techniques
Problem Solving TechniquesProblem Solving Techniques
Problem Solving Techniques
 
C programming notes
C programming notesC programming notes
C programming notes
 
C language 3
C language 3C language 3
C language 3
 
C programming notes.pdf
C programming notes.pdfC programming notes.pdf
C programming notes.pdf
 
C programming
C programmingC programming
C programming
 
Interview Questions For C Language
Interview Questions For C Language Interview Questions For C Language
Interview Questions For C Language
 
Interview Questions For C Language .pptx
Interview Questions For C Language .pptxInterview Questions For C Language .pptx
Interview Questions For C Language .pptx
 
fds unit1.docx
fds unit1.docxfds unit1.docx
fds unit1.docx
 
1. introduction to computer
1. introduction to computer1. introduction to computer
1. introduction to computer
 
Unit 1
Unit 1Unit 1
Unit 1
 
Aniket tore
Aniket toreAniket tore
Aniket tore
 
1584503386 1st chap
1584503386 1st chap1584503386 1st chap
1584503386 1st chap
 
Let's us c language (sabeel Bugti)
Let's us c language (sabeel Bugti)Let's us c language (sabeel Bugti)
Let's us c language (sabeel Bugti)
 
C programming Training in Ambala ! Batra Computer Centre
C programming Training in Ambala ! Batra Computer CentreC programming Training in Ambala ! Batra Computer Centre
C programming Training in Ambala ! Batra Computer Centre
 
Introduction to Computer and Programming - Lecture 03
Introduction to Computer and Programming - Lecture 03Introduction to Computer and Programming - Lecture 03
Introduction to Computer and Programming - Lecture 03
 
C programming course material
C programming course materialC programming course material
C programming course material
 
C_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptxC_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptx
 
Introduction to C Unit 1
Introduction to C Unit 1Introduction to C Unit 1
Introduction to C Unit 1
 

Recently uploaded

Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersChitralekhaTherkar
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptxPoojaSen20
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 

Recently uploaded (20)

Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of Powders
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 

C Data Types and Variables

  • 1. 1. Discuss the basic data types in C. C language is rich in data types. Data types refer to an extensive system used for declaring variables or functions of different types. The type of a variable determines how much space it occupies in storage and how the bit pattern stored is interpreted. There are 4 classes of data types: 1. Primary data types (int, float, char) 2. User defined data types (enumerator, typedef) 3. Derived data types (array, function, pointers, structure, union) 4. Empty data sets. (void)
  • 2. 2.What is a statement in C? Discuss the different types of statements in C, giving suitable examples of each. A statement is a command given to the computer that instructs the computer to take a specific action, such as display to the screen, or collect input. A computer program is made up of a series of statements. Labeled Statements A statement can be preceded by a label. Three types of labels exist in C. A simple identifier followed by a colon (:) is a label. Usually, this label is the target of a goto statement. Within switch statements, case and default labeled statements exist. A statement of the form case constant-expression : statement Compound Statements A compound statement is the way C groups multiple statements into a single statement. It consists of multiple statements and declarations within braces (i.e. { and }). The body of a function is also a compound statement by rule. Expression Statements An expression statement consists of an optional expression followed by a semicolon (;). If the expression is present, the statement may have a value. If no expression is present, the statement is often called the null statement.
  • 3. The printf function calls are expressions, so statements such as printf ("Hello World!n"); are expression statements. Selection Statements Three types of selection statements exist in C: if ( expression ) statement In this type of if-statement, the sub-statement will only be executed iff the expression is non-zero. if ( expression ) statement else statement Iteration Statements C has three kinds of iteration statements. The first is a while- statement with the form while ( expression ) statement The substatement of a while runs repeatedly as long as the control expression evaluates to non-zero at the beginning of each iteration. If the control expression evaluates to zero the first time through, the substatement may not run at all. The second is a do-while statement of the form do statement while ( expression ) ; This is similar to a while loop, except that the controlling expression is evaluated at the end of the loop instead of the beginning and consequently the sub-statement must execute at least once. The third type of iteration statement is the for-statement. In ANSI C 1989, it has the form
  • 4. for ( expressionopt ; expressionopt ; expressionopt ) statement In more recent versions of the C standard, a declaration can substitute for the first expression. The opt subscript indicates that the expression is optional. Jump Statements C has four types of jump statements. The first, the goto statement, is used sparingly and has the form goto identifier ; This statement transfers control flow to the statement labeled with the given identifier. The statement must be within the same function as the goto. The second, the break statement, with the form break ; is used within iteration statements and switch statements to pass control flow to the statement following the while, do-while, for, or switch. The third, the continue statement, with the form continue ; is used within the substatement of iteration statements to transfer control flow to the place just before the end of the substatement. In for statements the iteration expression (e3 above) will then be executed before the controlling expression (e2 above) is evaluated. The fourth type of jump statement is the return statement with the form
  • 5. return expressionopt ; This statement returns from the function. If the function return type is void, the function may not return a value; otherwise, the expression represents the value to be returned. 3. What is the role of the pre-processor in C? Explain the use of pre-processor directives like #include and #define with suitable examples. he C preprocessor is the macro preprocessor for the C, Objective- C and C++ computer programming languages. The preprocessor provides the ability for the inclusion of header files, macro expansions, conditional compilation, and line control. In many C implementations, it is a separate program invoked by the compiler as the first part of translation. The language of preprocessor directives is only weakly related to the grammar of C, and so is sometimes used to process other kinds of text files. 1. #define (Macros) A macro is a code that is replaced by some value of the code of macro. Any macro is mostly described and defined by its #define directive. Syntax: #define token value There are two types of macros: Function – like macros Object – like macros
  • 6. Function – like macros The function like-macro works almost like a function call. For example: #define MAX(a,b) ((a)>(b) ? (a): (b)) For example: #define MAX(a,b) ((a)>(b) ? (a): (b)) MAX here is the Macro name 2 #include There is some other functionality for the include preprocessor directive. It has its own three variants which replace the code with the current source files code. Three variants are as follows: #include<file> #include”file” Include anything else #include<file> Searches for a file in the defined list of the system or directories as specified then searches for a standard list of system libraries. #include”file” This type is used for your own customized header files of the program. A search is made for a file named file first in the current directory followed by system header files and current directories of directory current file. #include anything
  • 7. 4. Describe the ASCII Character Set, and discuss it’s importance in modern computing systems All the character sets used in the C language have their equivalent ASCII value. The ASCII value stands for American Standard Code for Information Interchange value. It consists of less than 256 characters, and we can represent these in 8 bits or even less. But we use a special type for accommodating and representing the larger sets of characters. These are called the wide-character type or wchat_t. However, a majority of the ANSI-compatible compilers in C accept these ASCII characters for both the character sets- the source and the execution. Every ASCII character will correspond to a specific numeric value. The character sets help in defining the valid characters that we can use in the source program or can interpret during the running of the program. For the source text, we have the source character set, while we have the execution character set that we use during the execution of any program. But we have various types of character sets. For instance, one of the character sets follows the basis of the ASCII character definitions, while the other set consists of various kanji characters (Japanese). The type of character set we use will have no impact on the compiler- but we must know that every character has different, unique values. The C language treats every character with different integer values.
  • 8. 5. Write a C program to calculate and display the volume (V) and area (A) of a sphere using the formulae: Area A = 4*PI*R2 and Volume = AR/3, where R is the radius. /* * C Program to Find Volume and Area of Sphere */ #include <stdio.h> #include <math.h> #define PI 3.14 int main() { float R; float A, volume; printf("Enter radius of the sphere : n"); scanf("%f", &R); A = 4 * PI * R * R; volume = A * R * 1/3; printf("area of sphere is: %f", A); printf("n Volume of sphere is : %f", volume); return 0; }
  • 9. 6. Write a program to read your name, roll number and CGPA and displays them to the screen. #include <stdio.h> struct student { char name[50]; int roll; float CGPA; } s; int main() { printf("Enter information:n"); printf("Enter name: "); fgets(s.name, sizeof(s.name), stdin); printf("Enter roll number: "); scanf("%d", &s.roll); printf("Enter CGPA: "); scanf("%f", &s.CGPA); printf("Displaying Information:n"); printf("Name: "); printf("%s", s.name); printf("Roll number: %dn", s.roll);
  • 10. printf("CGPA : %.1fn", s.CGPA); return 0; } 7. Write a C program that accepts a real number and prints the integral and fractional parts on the screen. #include <stdio.h> int main() { float num; printf("enter a number :") ; scanf("%f",&num); int num_integer = (int)num; float num_decimal = num - num_integer; printf("integer part: %d , fractional part : %fn",num_integer , num_decimal); return 0 ; } 8. Write a C program to convert a temperature reading in degrees Fahrenheit to degrees Celsius, using the formula: C = (5/9)x(F-32).
  • 11. #include<stdio.h> int main() { float F, Celsius; printf("Enter a temp in F: "); scanf("%f", &F); Celsius = ((F-32)*5)/9; printf("nn Temperature in Celsius is : %f",Celsius); return (0); } 9. What is meant by operator precedence and associativity? Build a table showing the associativity and relative precedence of various types of operators supported in C. Operator precedence determines the grouping of terms in an expression and decides how an expression is evaluated. Certain operators have higher precedence than others; for example, the multiplication operator has a higher precedence than the addition operator. Operators Associativity is used when two operators of same precedence appear in an expression. Associativity can be either Left to Right or Right to Left
  • 12. . 10. What is a unary operator? Discuss the purpose of any two unary operators supported by the C language. Also explain with a suitable code sample, the use of the conditional operator (?:).
  • 13. These are the type of operators that act upon just a single operand for producing a new value. All the unary operators have equal precedence, and their associativity is from right to left. When we combine the unary operator with an operand, we get the unary expression. Types of Unary Operator in C There are following types of unary operators found in the C language: unary minus (-) unary plus (+) decrement (- -) increment (++) NOT (!) sizeof () Address of operator (&) Unary Minus This operator changes the sign of any given argument. It means that a positive number will become negative, and a negative number will become positive. But the unary minus is different from that of the subtractor operator. It is because we require two operands for subtraction. int p = 20; int q = -p; // q = -20
  • 14. Unary Plus This operator changes the sign of any negative argument. It means that a negative number will become positive, and a positive number will also become positive. But the unary minus is different from that of the subtractor operator. It is because we require two operands for subtraction. int p = -20; int q = +p; // q = 20