[go: up one dir, main page]

0% found this document useful (0 votes)
30 views35 pages

Unit1 C Programming 29 09 2022

This document discusses the syntax and constructs of the C programming language. It covers variable declarations and naming conventions, data types, selection and looping constructs, and C keywords. It also provides examples of valid and invalid variable names. Finally, it lists some sample problems to solve involving calculations with variables and data types in C.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views35 pages

Unit1 C Programming 29 09 2022

This document discusses the syntax and constructs of the C programming language. It covers variable declarations and naming conventions, data types, selection and looping constructs, and C keywords. It also provides examples of valid and invalid variable names. Finally, it lists some sample problems to solve involving calculations with variables and data types in C.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 35

Unit-1

ANSI C
Syntax and Constructs of C
• Syntax is the grammar of any programming language.
• Every statement in C must end with semicolon(;)
• Variable declarations:
• Syntax : datatype variablename;
• examples: int sum; float area;
• Constructs of C
• Selection constructs: if, if ..else, if.. else if.. else and switch
• Looping constructs: while, do.. while and for
Syntax and Constructs of C
Variables
• Variable is an entity that has a value and is known to the program by
its name.
• Its can be changed during the execution of program
• It can only have one value at anytime during program execution
• Variables are stored in memory.
• in storage locations with unique address
Variable Naming
• Variable declaration:
• Syntax: datatype variablename;
• e.g. float radius; float area;
• All variable declarations should be after main() function call or before
its first use.
Variable Naming

• Every variable name/identifier can start with _ or alphabet but not a


number.
• It should not contain any other special symbols except _
• No blanks/spaces in between variable names are allowed
• Variable names are case-sensitive (max and Max are two different
names)
• Valid variable names: _radius,Radius,_fradius,radius1,
• Invalid variable names:1radius,radius$,1_radius,radius#,radius of circle, a’s,
”a”
C Keywords

• Keywords are used by C language. They have predefined meaning.


• They cannot be used as variable names/identifiers
• Examples: int, float, double, if , switch, case, else, break, continue,
while, do, for, main, return, typedef, enum, void, struct, union, signed,
long, unsigned, char,..
Test programs by clicking below link:
https://colab.research.google.com/drive/1BIJ40xvSaMuyeTb3B3DV3-wB3dGNKi6h?usp=sharing
Variable Naming-Hungarian Notation
• Variable Name: Hungarian Notation
• Syntax: datatype prefixQualifier;
• prefix: starting character of the variable datatype. always lowercase
• Qualifier: word (run-on words)that defines the purpose of variable usage. begins with
capital letter
• Examples
• To find Area of circle: float fRadius; float fArea;
• To find sum of two integers: int iFirstNumber=0; int iSecondNumber=0; int iSum;
• To read a character: char cLetter;
Lab Problems-5
1. Write a C program to read two numbers and display the product of two numbers.
2. Write a C program to read the radius and display the volume of sphere and surface
area of sphere.
3. Write a C program to read temperature in Fahrenheit and convert temperature from
Fahrenheit to centigrade. Test the program for the following values:68, 150, 0, 212, -
22, -200(degrees Fahrenheit)
4. Write a C program to swap two values without using temporary variable.
5. Write a C program to read the marks of 4 subjects of a student and find the average
marks scored.
6. Write a C program to calculate the mass of air in automobile tyre using formula
PV=0.37 m(T+460) where P =pressure, V=volume, m=mass of air, T=temperature in
Fahrenheit.

Note: Use Hungarian Notation while naming variables.

You might also like