C Programming 3

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 28

GATE Online Coaching

Classes
as per the Direction of
Ministry of Education
GOVERNMENT OF
ANDHRA PRADESH
PROGRAMMING CONCEPTS FOR GATE 2021
YouTube link is to be downloaded for every class on every
day as per the given schedule

https://jntua.ac.in/gate-online-classes/registration/
C Programming & Data Structures Weightage
Analysis
Year of GATE Weightage of Marks Topics Covered
Exam
2019 14 Marks C Programming, Recursion, Trees, Heaps
2018 9 Marks C Programming, Queues, Linked List, DFT, String
Functions
2017 Set 1: 11Marks C Programming, Queues, Linked List, Trees, Functions
Set 2: 14 Marks using static variables & pointers, structures
2016 Set 1: 12 Marks Algorithm analysis, Stacks & Queues, Height balanced
Set 2: 11 Marks tree, Heaps, quick sort, programming
2015 Set 1: 7 Marks Stacks & Queues, AVL trees, B Trees, C programming ,
Set 2: 11 Marks Hashing, Data Structures
Set 3: 18 Marks
Topics Covered
• Importance of C programming
• Developing programs in C
• Structure of C program
• Classification of Data Types
• Typical C Programs
• Online Test 1
Features of C Programming

Courtesy @ DataFlair

6
C Pros and Cons

Courtesy @ DataFlair

7
Developing Programs in C
There are mainly three steps:
1. Writing
2. Compiling
3. Executing
• Needs a text editor(integrated development environment), the C
compiler, assembler, and linker.
• C uses a semicolon as a statement terminator; to indicate that a statement
is complete.
• All program instructions - statements, have to be written in lower case
characters.
Program Development Steps
1)Statement of Problem 4.a)Compilation
a) Working with existing system and using proper Translate the program into machine code. This process is
questionnaire, the problem should be explained clearly. called as Compilation. Syntactic errors are found quickly at
b) What inputs are available, outputs are required and the time of compiling the program. These errors occur due
what is needed for creating workable solution should be to the usage of wrong syntaxes for the statements.
understood clearly. Eg: x=a*y+b
2)Analysis There is a syntax error in this statement, since, each and
a) The method of solutions to solve the problem can be every statement in C language ends with a semicolon (;).
identified.
b) We also judge that which method gives best results 4.b)Execution
among different methods of solution. The next step is Program execution. In this phase, we may
3)Designing encounter two types of errors.
a) Algorithms and flow charts will be prepared. Runtime Errors: these errors occur during the execution of
b) Keep focus on data, architecture, user interfaces and the program and terminates the program abnormally.
program components. Logical Errors: these errors occur due to incorrect usage of
4)Implementation the instructions in the program. These errors are neither
The algorithms and flow charts developed in the previous detected during compilation or execution nor cause any
steps are converted into actual programs in the high level stoppage to the program execution but produces incorrect
languages like C. outputs.
Developing Programs In C
It's time to write your first C program!

11
Structure of a C Program

12
13
Example of Block Comments

14
Example of Line Comments

15
What is the purpose of main() function
o Program execution starts from the main() function.
o Every C program must contain a main() function.
o May contain any number of statements- executed sequentially in the order
which they are written.
o It can in-turn call other functions.
o When main calls a function, it passes the execution control to that function. The
function returns control to main when a return statement is executed or when end of
function is reached.
o
o int main() //main with no arguments
o int main(int argc, char *argv[]) //main with arguments
o
o The parameters argc and argv respectively give the number and value of the
program's command-line arguments.

16
Some basic rules of writing a C program

1. Comments/Documentation
2. Statement termination by semicolon (;)
3. Tokens, identifiers related rules
4. Rules about identifier/variable declarations
5. Code indentation

17
Classification :Data Type
Basic Data Types: Size & Range

16 Bit Computer

32 Bit Computer
Specifiers or Modifiers
In addition, C has four type specifiers or modifiers
and three type qualifiers.
o Each of these type modifiers can be applied to the base type int.
o The modifiers signed and unsigned can also be applied to the base
type char.
o In addition, long can be applied to double.
o When the base type is omitted from a declaration, int is assumed.
o The type void does not have these modifiers.
Specifiers : Data Types
The specifiers and qualifiers for the data types can
be broadly classified into three types:
o Size specifiers— short and long
o Sign specifiers— signed and unsigned
o Type qualifiers— const, volatile and restrict

© Oxford University Press 2013. All


rights reserved.
-2b-1 to +(2b-1 -1)

0 to +(2b -1)
Data Types
The basic kinds of data that we will mostly use:
– Numeric
• Integers: whole number that can be negative, positive, or zero: ex. -
40, 0, 200, 19339.
• Real (floating point) numbers: whole number plus a decimal part. ex.
3.14159, 1.23e45
– Character (are enclosed by single quotes in C)
• All letters, numbers, and special symbols
– Ex. ‘A’, ‘+’, ‘5’
– String (are enclosed by double quotes in C)
• Are combinations of more than one character
– Ex. “programming”, “ME 30”
– Logical (also called ‘Boolean’ named after George Boole an English
mathematician from the early 1800’s)
• True or False (1 or 0)

23
Kinds of Data - Practice
Data Type

1. 17
If kind is ‘numeric’, then
2. “George” is it an integer or a
3. 2.35 floating point number?
4. 0.0023
5. -25
6. ‘m’
7. 4.32E-6
8. “185.3”
9. 0
10. 1

24
Kinds of Data - Practice
Data Type

1. 17 Unsigned int
If kind is ‘numeric’, then
2. “George” string is it an integer or a
3. 2.35 float floating point number?
4. 0.0023 float

5. -25 signed int

6. ‘m’ char

7. 4.32E-6 float

8. “185.3” string

9. 0 int or bool

10. 1 int or bool

25
Constants and Variables
• Constant
– A data element that never changes in your program
• 5, 62.37, 4.219E-6, “record_string”, ‘$’
• i = j + 7; /* which one is the constant? */
• first_letter = ‘a’; /* which one is the constant? */
• Variable
– A data element that can take on different values
• Its name represents a location (address) in memory
i = j + 7; /* which are variables? */
second_letter = ‘b’; /* which is the variable? */
• Values are ‘assigned’ using a single equal sign ( = )
Read the statement: i = j + 7;

NOTE!! Variables in C must be ‘declared’ before they can be used!

26
Declaring Variables and Data Types
• Variables must be declared before they can be used
– Gives info to the compiler about:
• How many bytes of memory to set aside
• How to interpret the bytes (data)
– Example:
int my_var; /* an integer variable my_var */
float sensor1; /* a float variable sensor1 */
char Letter01_a; /* a char variable Letter01_a */
• Two parts are needed in the declaration:
– Data type designator (e.g., int), (note, a ‘reserved word’)
– Identifier (i.e., a name: my_var), must be a valid identifier

27
TAKE TEST-1 BY TYPING ON YOUR
BROWSER

https://timify.me/form/eWJlg
MHmvdCr5SvX

You might also like