Problem Solving and 'C' Programming

Size: px
Start display at page:

Download "Problem Solving and 'C' Programming"

Transcription

1 Problem Solving and 'C' Programming Targeted at: Entry Level Trainees Session 10: Functions/Structure and Unions 2007, Cognizant Technology Solutions. All Rights Reserved. The information contained herein is subject to change without notice. C3: Protected

2 About the Author Created By: Jeyshankar Perumal (125623) Credential Information: Version and Date: Technical Skills: UNIX/C/C++/Oracle Experience: 8.5 Years PSC/PPT/1107/1.0 2

3 Icons Used Questions Tools Hands on Exercise Coding Standards Test Your Understanding Reference Try it Out A Welcome Break Contacts 3

4 Problem Solving and 'C' Programming Session 10: Overview Introduction: This session discusses about the storage classes, the command line arguments and the structures and it s operation. 4

5 Problem Solving and 'C' Programming Session 10: Objective Objective: After completing this session you will be able to:» Work with different storage classes in a program» Work with command line arguments» Explain the concept of structures and unions» Declare structure» Initialise structure» Perform operations on structures» Perform operation on structures and arrays» Perform operation on structures and functions 5

6 Storage Classes Variables in C can be characterized by their data type and storage classes. Data type refers to the type of information represented by a variable and storage classes define its life time and scope. Different storages classes available are:» auto» static» register» extern 6

7 Storage Classes (Contd.) The scope of the variable (where it can be used), is determined by where it is defined. If it is defined outside of all the blocks, then it has file scope. If a variable is defined in a block (encapsulated with and }), then its scope begins when the variable is defined and ends when it hits the terminating }. This is called block scope. 7

8 Storage Classes (Contd.) Life time refers to the permanence of a variable, that is, how long the variable will retain its value in memory. Syntax: stor-cls-specifier datatype vble-name,... 8

9 Automatic Variables: Auto Storage Class Automatic variables are local to the block in which they are declared. Local variables of different functions/blocks may have the same name. It retains its value till the control remains in that block. If not initialized, their initial value will be unpredictable. Stored in Memory. If no storage class is specified, by default it is an auto variable. 9

10 Automatic Variables: Auto Storage Class (Contd.) Example: main() } int a = 5 ; int a =6 ; printf ( %d, a); /*prints 6*/ } printf( %d, a); /*prints 5*/ 10

11 Static Variables: Static Storage Class Static variables are also local (visible) to the block in which the variable is declared. They retain the values throughout the life of the program. If not initialized in the declaration, it is automatically initialized to zero. Static variable values are stored in Memory. 11

12 Static Variables: Static Storage Class (Contd.) Example: main() int i; for (i=1;i<=5;i++) incre(); } incre() static int x = 0; x = x +1; printf( x = %d\n,x); } Output: x = 1 x = 2 x = 3 x = 4 12

13 Register Variables: Register Storage Class Registers are faster than memory, keeping the frequently accessed variables like a loop control variable in a register will increase the execution speed. Register variables are local (visible) to the block in which they declared. It retains its value till the control remains in that block. If not initialized, the variable is initialized to zero. 13

14 External Variables: Extern Storage Class External variables are not confined to a single function. Their scope extends from the point of definition through the remainder of the program. They are referred to as global variables. Access to variables outside of their file scope can also be made by using linkage. Linkage is done by placing the keyword extern prior to a variable declaration. This allows a variable that is defined in another source code file to be accessed. 14

15 External Variables: Extern Storage Class (Contd.) Example: int a = 5 ; /*external variable defination (no need to use extern keyword)*/ void main() extern int b; /*external vble declaration (the vble is declared somewhere else)*/ void fun(); fun(); printf( %d, a); /*prints 10*/ printf( %d, b); /*prints 20*/ } void fun() a = 10 ; } int b = 20; 15

16 Command Line Arguments A C program is executed by calling its main() function. The main() function is called with one integer argument indicating how many words are in the command line and another argument that is a character array of pointers containing the command line words. 16

17 Command Line Arguments (Contd.) main ( int argc, char *argv[]) : } argc provides a count of the number of command line arguments. argv is an array of character pointer of undefined size that can be thought of as an array of pointer to strings, which are command line strings. 17

18 Command Line Arguments (Contd.) Example: main( int argc, char* argv[]) } int i; printf( \n Total No. of Arguments =%d,argc); for( i = 0; i < argc; i++) printf( \narg. No. %d = %s,i, argv[i]); 18

19 Command Line Arguments (Contd.) When the following command is given in the command prompt, for the above program: C:\tc\bin> CMLPGM c cpp java» Where: CMLPGM is program name c cpp java arguments The following result is displayed: Total No. of Arguments = 4 Arg. No. 0 = CMLPGM Arg. No. 1 = c Arg. No. 2 = cpp Arg. No. 3 = java 19

20 Introduction to Structures and Unions Structures and Unions are the main constructs available in C through which programmers can define new data type. Structures and unions provide a way to group logically related data items together. 20

21 Structure The structure is a derived data type used to represent heterogeneous data. A structure is an aggregation of components that can be treated as a single variable. The components are called members. For example, an employee is represented with the following attributes:» employee code (alphanumeric)» employee name (string)» department code (integer)» salary (float) 21

22 Structure: Declaration Structures are defined via a template and declared with a tag which helps to avoid repeating the definition. struct keyword is used to define structures. struct tag_name type variable-name, variable-name,...; type variable-name, variable-name,...; type variable-name, variable-name,...; : : type variable-name, variable-name,...; }; 22

23 Structure: Declaration (Contd.) Structure-variables can be declared anywhere in the program. Syntax: struct tag_name new-structure-variable; Example: struct employee int code; char name[20]; int dept_code; float salary; }; struct employee emp1, emp2; 23

24 Structure: Declaration (Contd.) Structure definition and declaration of structure variables can be combined together. Example: struct employee int code; char name[20]; int dept_code; float salary; } emp1, emp2; Note: Tag name is optional in this case. 24

25 Structure: Initialization Structure variables can be initialized at the time of declaration If the structure variable is declared before the main function, the member variables are automatically initialized to zero or Null. If it is partially initialized, then uninitialized members will be assigned zero or Null character. 25

26 Accessing the Members Members of the structure can be accessed by using the member access operator. (dot) Syntax: struct_vble.member-field-name Example: emp1.code emp1.name emp1.dept_code emp1.salary emp2.code emp2.name 26

27 Operations on Structures Each member of a structure can be assigned to the corresponding member of another structure. Structure can also be assigned to another Structure provided they have the same composition. sizeof() operator can be used to find the size of the structure. 27

28 Operations on Structures (Contd.) Two structure variables cannot be compared for equality, even though the values stored in the member variables are the same. This is because slack bytes are added in between two member variables and these slack bytes have some garbage value. 28

29 Nested Structures Structures can contain members that themselves are structures. struct date int day; int month; int year; }; struct employee int code; char name [20]; struct date doj ; int dept_code; float salary; }emp1,emp2; 29

30 Structures and Arrays The members of structures can be arrays and the structure can also be an array Example: The following example is a array of structures: struct stud int rollnum; char name[20]; int semester; int avg; }; struct stud student[50]; Accessing values: student[1].rollnum, student[1].name, student[1].semester, student[1].avg 30

31 Arrays Within Structures Example: struct student-mark int rollnumber; char name[15]; int sub_marks[5]; } student; Accessing values: student.sub_marks[0], student.sub_mark[1], student.name 31

32 Self-Referential Structures A structure containing a member which is a pointer to the same structure type is called self-referential structures. It is used to build various kinds of linked data structures. Example: struct employee char name[20]; char gender; float salary; struct employee *empptr; }; 32

33 Structures and Functions Structures can be passed to a function using call by value and call by reference methods. By default the structure is passed using call by value approach to a function. For calling by reference, structure should be a array of structures or structure variable should be pointer variable. 33

34 Structures and Functions (Contd.) Example: Passing structures to a function (call by value): struct emp int empno; char empname[10]; }; void main( ) void display(struct emp); struct emp emp1 = 101, AAAA } ; display(emp1); } void display(struct emp emp2) printf( %d, emp2.empno); printf( %s, emp2.empname); } 34

35 Structures and Functions (Contd.) Example: Passing structures to a function (call by reference): struct emp int empno; char empname[10]; }; void main( ) void change(struct emp *); struct emp emp1 = 101, AAAA } ; change(&emp1); printf( %d, emp1->empno); /*prints 102*/ } void change (struct emp *emp2) emp2->empno =102; } 35

36 Q & A Allow time for questions from participants 36

37 Try it Out: 1 Problem Statement: Write a program to convert given weight in pounds to Imperial and international units 37

38 Try it Out: 1 (Contd.) Code: #include <stdio.h> void print_converted(int pounds) /* Convert U.S. Weight to Imperial and International Units. Print the results */ int stones = pounds / 14; int uklbs = pounds % 14; float kilos_per_pound = ; float kilos = pounds * kilos_per_pound; } printf(" %3d %2d %2d pounds, stones, uklbs, kilos); %6.2f\n", main(int argc,char *argv[]) int pounds; Refer File Name : <ses10_1.c> for soft copy of the code 38

39 Try it Out: 1 (Contd.) Code: if(argc!= 2) printf("usage: convert weight_in_pounds\n"); exit(1); } } sscanf(argv[1], "%d", &pounds); /* Convert String to int */ printf(" US lbs UK st. lbs INT Kg\n"); print_converted(pounds); getchar(); Refer File Name : <ses10_1.c> for soft copy of the code 39

40 Try it Out: 1 (Contd.) How it Works: This program explains how to use command line arguments. While running the program pass the weight which needs to be converted in to different units as input argument Read the command line argument, convert the pound in to different units by applying formula. Print the values on the screen 40

41 Try it Out: 2 Problem Statement: Write a program to store values in a structure and pass the structure to a function and print the values on the screen 41

42 Try it Out: 2 (Contd.) Code: #include <stdio.h> struct s_type int i; double d; } var1; void f(struct s_type temp); void main(void) var1.i=99; var1.d = 98.6; f(var1); getchar(); } void f(struct s_type temp) printf("%d %1f", temp.i, temp.d); } Refer File Name : <ses10_2.c> for soft copy of the code 42

43 Try it Out: 2 (Contd.) How it Works: In this program, declare a structure comprising of two different data type members Assign values to each member of a structure. Pass the structure in a function, where it access each member of structure and print it on the screen 43

44 Q & A Allow time for questions from participants 44

45 Test Your Understanding 1. State whether the following statements are True or False: a) The tag name of a structure is optional. b) Structures may contain members of only one data type. c) Structure members will share the memory locations. 2. Write a Program to perform basic banking operations using array of structures. 45

46 Problem Solving and 'C' Programming Session 10: Summary C supports four storage class specifiers (auto, static, extern, and register) to define scope and life time for the variable. The command line arguments argc, argv are used to pass arguments to main() function. Structure is a derived data type which is used to store heterogeneous data items under a single unit. Structure members can be accessed by structure variables using dot operator. Structures can be nested and can have self reference also. Structure can be passed to a function by both call by value approach and call by reference approach. 46

47 Problem Solving and 'C' Programming Session 10: Source C Reference Card (ANSI) C Reference Manual by Dennis Ritchie Programming in C: A Tutorial by Brian W. Kernighan, Bell Laboratories Byron Gottfried, Programming in C, Tata McGraw Hill Deitel & Deitel, C How to Program, Third Edition, Prentice Hall Disclaimer: Parts of the content of this course is based on the materials available from the Web sites and books listed above. The materials that can be accessed from linked sites are not maintained by Cognizant Academy and we are not responsible for the contents thereof. All trademarks, service marks, and trade names in this course are the marks of the respective owner(s). 47

48 You have completed the Session 10 of Problem Solving and 'C' Programming 2007, Cognizant Technology Solutions. All Rights Reserved. The information contained herein is subject to change without notice.

Problem Solving and 'C' Programming

Problem Solving and 'C' Programming Problem Solving and 'C' Programming Targeted at: Entry Level Trainees Session 05: Selection and Control Structures 2007, Cognizant Technology Solutions. All Rights Reserved. The information contained herein

More information

Problem Solving and 'C' Programming

Problem Solving and 'C' Programming Problem Solving and 'C' Programming Targeted at: Entry Level Trainees Session 15: Files and Preprocessor Directives/Pointers 2007, Cognizant Technology Solutions. All Rights Reserved. The information contained

More information

ALQUDS University Department of Computer Engineering

ALQUDS University Department of Computer Engineering 2013/2014 Programming Fundamentals for Engineers Lab Lab Session # 8 Structures, and Enumeration ALQUDS University Department of Computer Engineering Objective: After completing this lab, the students

More information

Programming in C. What is C?... What is C?

Programming in C. What is C?... What is C? C Programming in C UVic SEng 265 Developed by Brian Kernighan and Dennis Ritchie of Bell Labs Earlier, in 1969, Ritchie and Thompson developed the Unix operating system We will be focusing on a version

More information

Programming in C UVic SEng 265

Programming in C UVic SEng 265 Programming in C UVic SEng 265 Daniel M. German Department of Computer Science University of Victoria 1 SEng 265 dmgerman@uvic.ca C Developed by Brian Kernighan and Dennis Ritchie of Bell Labs Earlier,

More information

Programming in C. What is C?... What is C?

Programming in C. What is C?... What is C? Programming in C UVic SEng 265 C Developed by Brian Kernighan and Dennis Ritchie of Bell Labs Earlier, in 1969, Ritchie and Thompson developed the Unix operating system We will be focusing on a version

More information

CS561 Manju Muralidharan Priya Structures in C CS200 STRUCTURES. Manju Muralidharan Priya

CS561 Manju Muralidharan Priya Structures in C CS200 STRUCTURES. Manju Muralidharan Priya OBJECTIVES: CS200 STRUCTURES Manju Muralidharan Priya By the end of this class you will have understood: 1. Definition of a structure 2. Nested Structures 3. Arrays of structure 4. User defined data types

More information

IV Unit Second Part STRUCTURES

IV Unit Second Part STRUCTURES STRUCTURES IV Unit Second Part Structure is a very useful derived data type supported in c that allows grouping one or more variables of different data types with a single name. The general syntax of structure

More information

UNIT-V. Structures. The general syntax of structure is given below: Struct <tagname> { datatype membername1; datatype membername2; };

UNIT-V. Structures. The general syntax of structure is given below: Struct <tagname> { datatype membername1; datatype membername2; }; UNIT-V Structures Structure is a very useful derived data type supported in c that allows grouping one or more variables of different data types with a single name. The general syntax of structure is given

More information

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University Unit 1 Programming Language and Overview of C 1. State whether the following statements are true or false. a. Every line in a C program should end with a semicolon. b. In C language lowercase letters are

More information

Unit 7. Functions. Need of User Defined Functions

Unit 7. Functions. Need of User Defined Functions Unit 7 Functions Functions are the building blocks where every program activity occurs. They are self contained program segments that carry out some specific, well defined task. Every C program must have

More information

Unit IV & V Previous Papers 1 mark Answers

Unit IV & V Previous Papers 1 mark Answers 1 What is pointer to structure? Pointer to structure: Unit IV & V Previous Papers 1 mark Answers The beginning address of a structure can be accessed through the use of the address (&) operator If a variable

More information

Subject: Fundamental of Computer Programming 2068

Subject: Fundamental of Computer Programming 2068 Subject: Fundamental of Computer Programming 2068 1 Write an algorithm and flowchart to determine whether a given integer is odd or even and explain it. Algorithm Step 1: Start Step 2: Read a Step 3: Find

More information

C: How to Program. Week /Mar/05

C: How to Program. Week /Mar/05 1 C: How to Program Week 2 2007/Mar/05 Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers

More information

Storage class in C. Automatic variables External variables Static variables Register variables Scopes and longevity of above types of variables.

Storage class in C. Automatic variables External variables Static variables Register variables Scopes and longevity of above types of variables. 1 Storage class in C Automatic variables External variables Static variables Register variables Scopes and longevity of above types of variables. 2 Few terms 1. Scope: the scope of a variable determines

More information

Course Code : MCS-011 Course Title : Problem Solving and Programming Assignment Number : MCA(1)/011/Assign/13 Maximum Marks : 100 Weightage : 25%

Course Code : MCS-011 Course Title : Problem Solving and Programming Assignment Number : MCA(1)/011/Assign/13 Maximum Marks : 100 Weightage : 25% For more IGNOU Solved Assignments visit www.ignouhelp.in Get Daily Updates by Facebook: https://www.facebook.com/ignouhelp.in Course Code : MCS011 Course Title : Problem Solving and Programming Assignment

More information

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14 C introduction Variables Variables 1 / 14 Contents Variables Data types Variable I/O Variables 2 / 14 Usage Declaration: t y p e i d e n t i f i e r ; Assignment: i d e n t i f i e r = v a l u e ; Definition

More information

Fundamentals of Programming Session 12

Fundamentals of Programming Session 12 Fundamentals of Programming Session 12 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Fall 2014 These slides have been created using Deitel s slides Sharif University of Technology Outlines

More information

3.3 Structures. Department of CSE

3.3 Structures. Department of CSE 3.3 Structures 1 Department of CSE Objectives To give an introduction to Structures To clearly distinguish between Structures from Arrays To explain the scenarios which require Structures To illustrate

More information

C Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

C Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee C Language Part 1 (Minor modifications by the instructor) References C for Python Programmers, by Carl Burch, 2011. http://www.toves.org/books/cpy/ The C Programming Language. 2nd ed., Kernighan, Brian,

More information

From Java to C. Thanks to Randal E. Bryant and David R. O'Hallaron (Carnegie-Mellon University) for providing the basis for these slides

From Java to C. Thanks to Randal E. Bryant and David R. O'Hallaron (Carnegie-Mellon University) for providing the basis for these slides From Java to C Thanks to Randal E. Bryant and David R. O'Hallaron (Carnegie-Mellon University) for providing the basis for these slides 1 Outline Overview comparison of C and Java Good evening Preprocessor

More information

Memory. What is memory? How is memory organized? Storage for variables, data, code etc. Text (Code) Data (Constants) BSS (Global and static variables)

Memory. What is memory? How is memory organized? Storage for variables, data, code etc. Text (Code) Data (Constants) BSS (Global and static variables) Memory Allocation Memory What is memory? Storage for variables, data, code etc. How is memory organized? Text (Code) Data (Constants) BSS (Global and static variables) Text Data BSS Heap Stack (Local variables)

More information

C Introduction. Comparison w/ Java, Memory Model, and Pointers

C Introduction. Comparison w/ Java, Memory Model, and Pointers CS 261 Fall 2018 Mike Lam, Professor C Introduction Comparison w/ Java, Memory Model, and Pointers Please go to socrative.com on your phone or laptop, choose student login and join room LAMJMU The C Language

More information

High Performance Computing MPI and C-Language Seminars 2009

High Performance Computing MPI and C-Language Seminars 2009 High Performance Computing - Seminar Plan Welcome to the High Performance Computing seminars for 2009. Aims: Introduce the C Programming Language. Basic coverage of C and programming techniques needed

More information

Unit 8. Structures and Unions. School of Science and Technology INTRODUCTION

Unit 8. Structures and Unions. School of Science and Technology INTRODUCTION INTRODUCTION Structures and Unions Unit 8 In the previous unit 7 we have studied about C functions and their declarations, definitions, initializations. Also we have learned importance of local and global

More information

Binghamton University. CS-211 Fall Variable Scope

Binghamton University. CS-211 Fall Variable Scope Variable Scope 1 2 Scope The places in your code that can read and/or write a variable. Scope starts at the location where you declare the variable There may be holes in the scope! Scope ends at the end

More information

Outline. Lecture 1 C primer What we will cover. If-statements and blocks in Python and C. Operators in Python and C

Outline. Lecture 1 C primer What we will cover. If-statements and blocks in Python and C. Operators in Python and C Lecture 1 C primer What we will cover A crash course in the basics of C You should read the K&R C book for lots more details Various details will be exemplified later in the course Outline Overview comparison

More information

Functions in C C Programming and Software Tools. N.C. State Department of Computer Science

Functions in C C Programming and Software Tools. N.C. State Department of Computer Science Functions in C C Programming and Software Tools N.C. State Department of Computer Science Functions in C Functions are also called subroutines or procedures One part of a program calls (or invokes the

More information

UNIT - V STRUCTURES AND UNIONS

UNIT - V STRUCTURES AND UNIONS UNIT - V STRUCTURES AND UNIONS STRUCTURE DEFINITION A structure definition creates a format that may be used to declare structure variables. Let us use an example to illustrate the process of structure

More information

C Language, Token, Keywords, Constant, variable

C Language, Token, Keywords, Constant, variable C Language, Token, Keywords, Constant, variable A language written by Brian Kernighan and Dennis Ritchie. This was to be the language that UNIX was written in to become the first "portable" language. C

More information

CS 261 Fall C Introduction. Variables, Memory Model, Pointers, and Debugging. Mike Lam, Professor

CS 261 Fall C Introduction. Variables, Memory Model, Pointers, and Debugging. Mike Lam, Professor CS 261 Fall 2017 Mike Lam, Professor C Introduction Variables, Memory Model, Pointers, and Debugging The C Language Systems language originally developed for Unix Imperative, compiled language with static

More information

Array Initialization

Array Initialization Array Initialization Array declarations can specify initializations for the elements of the array: int primes[10] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 ; initializes primes[0] to 2, primes[1] to 3, primes[2]

More information

C LANGUAGE AND ITS DIFFERENT TYPES OF FUNCTIONS

C LANGUAGE AND ITS DIFFERENT TYPES OF FUNCTIONS C LANGUAGE AND ITS DIFFERENT TYPES OF FUNCTIONS Manish Dronacharya College Of Engineering, Maharishi Dayanand University, Gurgaon, Haryana, India III. Abstract- C Language History: The C programming language

More information

Programming and Data Structure

Programming and Data Structure Programming and Data Structure Sujoy Ghose Sudeshna Sarkar Jayanta Mukhopadhyay Dept. of Computer Science & Engineering. Indian Institute of Technology Kharagpur Spring Semester 2012 Programming and Data

More information

COMP 2355 Introduction to Systems Programming

COMP 2355 Introduction to Systems Programming COMP 2355 Introduction to Systems Programming Christian Grothoff christian@grothoff.org http://grothoff.org/christian/ 1 Functions Similar to (static) methods in Java without the class: int f(int a, int

More information

C PROGRAMMING QUESTIONS AND

C PROGRAMMING QUESTIONS AND 8/26/2011 C C PROGRAMMING QUESTIONS AND ANSWER http://cquestionbank.blogspot.com Ritesh kumar (1) What will be output if you will compile and execute the following c code? struct marks{ int p:3; int c:3;

More information

Syntax and Variables

Syntax and Variables Syntax and Variables What the Compiler needs to understand your program, and managing data 1 Pre-Processing Any line that starts with # is a pre-processor directive Pre-processor consumes that entire line

More information

Programming Language Basics

Programming Language Basics Programming Language Basics Lecture Outline & Notes Overview 1. History & Background 2. Basic Program structure a. How an operating system runs a program i. Machine code ii. OS- specific commands to setup

More information

VARIABLES AND CONSTANTS

VARIABLES AND CONSTANTS UNIT 3 Structure VARIABLES AND CONSTANTS Variables and Constants 3.0 Introduction 3.1 Objectives 3.2 Character Set 3.3 Identifiers and Keywords 3.3.1 Rules for Forming Identifiers 3.3.2 Keywords 3.4 Data

More information

TDDB68 Concurrent Programming and Operating Systems. Lecture 2: Introduction to C programming

TDDB68 Concurrent Programming and Operating Systems. Lecture 2: Introduction to C programming TDDB68 Concurrent Programming and Operating Systems Lecture 2: Introduction to C programming Mikael Asplund, Senior Lecturer Real-time Systems Laboratory Department of Computer and Information Science

More information

Basic Elements of C. Staff Incharge: S.Sasirekha

Basic Elements of C. Staff Incharge: S.Sasirekha Basic Elements of C Staff Incharge: S.Sasirekha Basic Elements of C Character Set Identifiers & Keywords Constants Variables Data Types Declaration Expressions & Statements C Character Set Letters Uppercase

More information

Chapter 1 & 2 Introduction to C Language

Chapter 1 & 2 Introduction to C Language 1 Chapter 1 & 2 Introduction to C Language Copyright 2007 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 1 & 2 - Introduction to C Language 2 Outline 1.1 The History

More information

Chapter 2 - Introduction to C Programming

Chapter 2 - Introduction to C Programming Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers 2.4 Memory Concepts 2.5 Arithmetic

More information

M3-R4: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE

M3-R4: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE M3-R4: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE NOTE: 1. There are TWO PARTS in this Module/Paper. PART ONE contains FOUR questions and PART TWO contains FIVE questions. 2. PART ONE is to be

More information

M1-R4: Programing and Problem Solving using C (JAN 2019)

M1-R4: Programing and Problem Solving using C (JAN 2019) M1-R4: Programing and Problem Solving using C (JAN 2019) Max Marks: 100 M1-R4-07-18 DURATION: 03 Hrs 1. Each question below gives a multiple choice of answers. Choose the most appropriate one and enter

More information

CS10001: Programming & Data Structures. Dept. of Computer Science & Engineering

CS10001: Programming & Data Structures. Dept. of Computer Science & Engineering CS10001: Programming & Data Structures Dept. of Computer Science & Engineering 1 Course Materials Books: 1. Programming with C (Second Edition) Byron Gottfried, Third Edition, Schaum s Outlines Series,

More information

Storage class and Scope:

Storage class and Scope: Algorithm = Logic + Control + Data Data structures and algorithms Data structures = Ways of systematically arranging information, both abstractly and concretely Algorithms = Methods for constructing, searching,

More information

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 13, FALL 2012

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 13, FALL 2012 CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 13, FALL 2012 TOPICS TODAY Project 5 Pointer Basics Pointers and Arrays Pointers and Strings POINTER BASICS Java Reference In Java,

More information

Binghamton University. CS-211 Fall Variable Scope

Binghamton University. CS-211 Fall Variable Scope Variable Scope 1 Scope The places in your code that can read and/or write a variable. Scope starts at the location where you declare the variable There may be holes in the scope! Scope ends at the end

More information

About Codefrux While the current trends around the world are based on the internet, mobile and its applications, we try to make the most out of it. As for us, we are a well established IT professionals

More information

Review of the C Programming Language for Principles of Operating Systems

Review of the C Programming Language for Principles of Operating Systems Review of the C Programming Language for Principles of Operating Systems Prof. James L. Frankel Harvard University Version of 7:26 PM 4-Sep-2018 Copyright 2018, 2016, 2015 James L. Frankel. All rights

More information

Principles of C and Memory Management

Principles of C and Memory Management COMP281 Lecture 9 Principles of C and Memory Management Dr Lei Shi Last Lecture Today Pointer to Array Pointer Arithmetic Pointer with Functions struct Storage classes typedef union String struct struct

More information

Binghamton University. CS-211 Fall Variable Scope

Binghamton University. CS-211 Fall Variable Scope Variable Scope 1 Scope The places in your code that can read and/or write a variable. Scope starts at the location where you declare the variable There may be holes in the scope! Scope ends at the end

More information

Introduction to C Language

Introduction to C Language Introduction to C Language Instructor: Professor I. Charles Ume ME 6405 Introduction to Mechatronics Fall 2006 Instructor: Professor Charles Ume Introduction to C Language History of C Language In 1972,

More information

Structure of this course. C and C++ Past Exam Questions. Text books

Structure of this course. C and C++ Past Exam Questions. Text books Structure of this course C and C++ 1. Types Variables Expressions & Statements Alastair R. Beresford University of Cambridge Lent Term 2008 Programming in C: types, variables, expressions & statements

More information

Subject: PROBLEM SOLVING THROUGH C Time: 3 Hours Max. Marks: 100

Subject: PROBLEM SOLVING THROUGH C Time: 3 Hours Max. Marks: 100 Code: DC-05 Subject: PROBLEM SOLVING THROUGH C Time: 3 Hours Max. Marks: 100 NOTE: There are 11 Questions in all. Question 1 is compulsory and carries 16 marks. Answer to Q. 1. must be written in the space

More information

Example: Structure, Union. Syntax. of Structure: struct book { char title[100]; char author[50] ]; float price; }; void main( )

Example: Structure, Union. Syntax. of Structure: struct book { char title[100]; char author[50] ]; float price; }; void main( ) Computer Programming and Utilization ( CPU) 110003 Structure, Union 1 What is structure? How to declare a Structure? Explain with Example Structure is a collection of logically related data items of different

More information

Deccan Education Society s FERGUSSON COLLEGE, PUNE (AUTONOMOUS) SYLLABUS UNDER AUTONOMY. FIRST YEAR B.Sc. COMPUTER SCIENCE SEMESTER I

Deccan Education Society s FERGUSSON COLLEGE, PUNE (AUTONOMOUS) SYLLABUS UNDER AUTONOMY. FIRST YEAR B.Sc. COMPUTER SCIENCE SEMESTER I Deccan Education Society s FERGUSSON COLLEGE, PUNE (AUTONOMOUS) SYLLABUS UNDER AUTONOMY FIRST YEAR B.Sc. COMPUTER SCIENCE SEMESTER I SYLLABUS OF COMPUTER SCIENCE Academic Year 2016-2017 Deccan Education

More information

Procedures, Parameters, Values and Variables. Steven R. Bagley

Procedures, Parameters, Values and Variables. Steven R. Bagley Procedures, Parameters, Values and Variables Steven R. Bagley Recap A Program is a sequence of statements (instructions) Statements executed one-by-one in order Unless it is changed by the programmer e.g.

More information

IMPORTANT QUESTIONS IN C FOR THE INTERVIEW

IMPORTANT QUESTIONS IN C FOR THE INTERVIEW IMPORTANT QUESTIONS IN C FOR THE INTERVIEW 1. What is a header file? Header file is a simple text file which contains prototypes of all in-built functions, predefined variables and symbolic constants.

More information

Why Pointers. Pointers. Pointer Declaration. Two Pointer Operators. What Are Pointers? Memory address POINTERVariable Contents ...

Why Pointers. Pointers. Pointer Declaration. Two Pointer Operators. What Are Pointers? Memory address POINTERVariable Contents ... Why Pointers Pointers They provide the means by which functions can modify arguments in the calling function. They support dynamic memory allocation. They provide support for dynamic data structures, such

More information

C BOOTCAMP DAY 2. CS3600, Northeastern University. Alan Mislove. Slides adapted from Anandha Gopalan s CS132 course at Univ.

C BOOTCAMP DAY 2. CS3600, Northeastern University. Alan Mislove. Slides adapted from Anandha Gopalan s CS132 course at Univ. C BOOTCAMP DAY 2 CS3600, Northeastern University Slides adapted from Anandha Gopalan s CS132 course at Univ. of Pittsburgh Pointers 2 Pointers Pointers are an address in memory Includes variable addresses,

More information

CSE 303 Lecture 8. Intro to C programming

CSE 303 Lecture 8. Intro to C programming CSE 303 Lecture 8 Intro to C programming read C Reference Manual pp. Ch. 1, 2.2-2.4, 2.6, 3.1, 5.1, 7.1-7.2, 7.5.1-7.5.4, 7.6-7.9, Ch. 8; Programming in C Ch. 1-6 slides created by Marty Stepp http://www.cs.washington.edu/303/

More information

Quiz 0 Answer Key. Answers other than the below may be possible. Multiple Choice. 0. a 1. a 2. b 3. c 4. b 5. d. True or False.

Quiz 0 Answer Key. Answers other than the below may be possible. Multiple Choice. 0. a 1. a 2. b 3. c 4. b 5. d. True or False. Quiz 0 Answer Key Answers other than the below may be possible. Multiple Choice. 0. a 1. a 2. b 3. c 4. b 5. d True or False. 6. T or F 7. T 8. F 9. T 10. T or F Itching for Week 0? 11. 00011001 + 00011001

More information

PROGRAMMAZIONE I A.A. 2017/2018

PROGRAMMAZIONE I A.A. 2017/2018 PROGRAMMAZIONE I A.A. 2017/2018 FUNCTIONS INTRODUCTION AND MAIN All the instructions of a C program are contained in functions. üc is a procedural language üeach function performs a certain task A special

More information

CS6202 - PROGRAMMING & DATA STRUCTURES UNIT I Part - A 1. W hat are Keywords? Keywords are certain reserved words that have standard and pre-defined meaning in C. These keywords can be used only for their

More information

C PROGRAMMING Lecture 4. 1st semester

C PROGRAMMING Lecture 4. 1st semester C PROGRAMMING Lecture 4 1st semester 2017-2018 Structures Structure: Collection of one or more variables a tool for grouping heterogeneous elements together (different types) Array: a tool for grouping

More information

Model Viva Questions for Programming in C lab

Model Viva Questions for Programming in C lab Model Viva Questions for Programming in C lab Title of the Practical: Assignment to prepare general algorithms and flow chart. Q1: What is a flowchart? A1: A flowchart is a diagram that shows a continuous

More information

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath UNIT - I Introduction to C Programming Introduction to C C was originally developed in the year 1970s by Dennis Ritchie at Bell Laboratories, Inc. C is a general-purpose programming language. It has been

More information

ELEC 377 C Programming Tutorial. ELEC Operating Systems

ELEC 377 C Programming Tutorial. ELEC Operating Systems ELE 377 Programming Tutorial Outline! Short Introduction! History & Memory Model of! ommon Errors I have seen over the years! Work through a linked list example on the board! - uses everything I talk about

More information

Downloaded S. from Kiran, PGT (CS) KV, Malleswaram STRUCTURES. Downloaded from

Downloaded S. from Kiran,  PGT (CS) KV, Malleswaram STRUCTURES. Downloaded from Downloaded S. from Kiran, www.studiestoday.com PGT (CS) KV, STRUCTURES WHAT IS A STRUCTURE? Structure is a collection of logically related data. It is also a collection of dissimilar datatype. Downloaded

More information

Structured Programming. Functions and Structured Programming. Functions. Variables

Structured Programming. Functions and Structured Programming. Functions. Variables Structured Programming Functions and Structured Programming Structured programming is a problem-solving strategy and a programming methodology. The construction of a program should embody topdown design

More information

Programming in C and C++

Programming in C and C++ Programming in C and C++ 1. Types Variables Expressions & Statements Dr. Anil Madhavapeddy University of Cambridge (based on previous years thanks to Alan Mycroft, Alastair Beresford and Andrew Moore)

More information

gcc hello.c a.out Hello, world gcc -o hello hello.c hello Hello, world

gcc hello.c a.out Hello, world gcc -o hello hello.c hello Hello, world alun@debian:~$ gcc hello.c alun@debian:~$ a.out Hello, world alun@debian:~$ gcc -o hello hello.c alun@debian:~$ hello Hello, world alun@debian:~$ 1 A Quick guide to C for Networks and Operating Systems

More information

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 14

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 14 BIL 104E Introduction to Scientific and Engineering Computing Lecture 14 Because each C program starts at its main() function, information is usually passed to the main() function via command-line arguments.

More information

CE221 Programming in C++ Part 1 Introduction

CE221 Programming in C++ Part 1 Introduction CE221 Programming in C++ Part 1 Introduction 06/10/2017 CE221 Part 1 1 Module Schedule There are two lectures (Monday 13.00-13.50 and Tuesday 11.00-11.50) each week in the autumn term, and a 2-hour lab

More information

EL6483: Brief Overview of C Programming Language

EL6483: Brief Overview of C Programming Language EL6483: Brief Overview of C Programming Language EL6483 Spring 2016 EL6483 EL6483: Brief Overview of C Programming Language Spring 2016 1 / 30 Preprocessor macros, Syntax for comments Macro definitions

More information

(heavily based on last year s notes (Andrew Moore) with thanks to Alastair R. Beresford. 1. Types Variables Expressions & Statements 2/23

(heavily based on last year s notes (Andrew Moore) with thanks to Alastair R. Beresford. 1. Types Variables Expressions & Statements 2/23 Structure of this course Programming in C: types, variables, expressions & statements functions, compilation, pre-processor pointers, structures extended examples, tick hints n tips Programming in C++:

More information

Programming Fundamentals (CS 302 ) Dr. Ihsan Ullah. Lecturer Department of Computer Science & IT University of Balochistan

Programming Fundamentals (CS 302 ) Dr. Ihsan Ullah. Lecturer Department of Computer Science & IT University of Balochistan Programming Fundamentals (CS 302 ) Dr. Ihsan Ullah Lecturer Department of Computer Science & IT University of Balochistan 1 Outline p Introduction p Program development p C language and beginning with

More information

Course Title: C Programming Full Marks: Course no: CSC110 Pass Marks: Nature of course: Theory + Lab Credit hours: 3

Course Title: C Programming Full Marks: Course no: CSC110 Pass Marks: Nature of course: Theory + Lab Credit hours: 3 Detailed Syllabus : Course Title: C Programming Full Marks: 60+20+20 Course no: CSC110 Pass Marks: 24+8+8 Nature of course: Theory + Lab Credit hours: 3 Course Description: This course covers the concepts

More information

Lecture 03 Bits, Bytes and Data Types

Lecture 03 Bits, Bytes and Data Types Lecture 03 Bits, Bytes and Data Types Computer Languages A computer language is a language that is used to communicate with a machine. Like all languages, computer languages have syntax (form) and semantics

More information

Contents. Custom data type struct data type Fixed length memory Alias data type

Contents. Custom data type struct data type Fixed length memory Alias data type Complex Data Type Contents Custom data type struct data type Fixed length memory Alias data type Custom data type Terminology primitive data type the data type that don't need to be defined; they are already

More information

Algorithms, Data Structures, and Problem Solving

Algorithms, Data Structures, and Problem Solving Algorithms, Data Structures, and Problem Solving Masoumeh Taromirad Hamlstad University DT4002, Fall 2016 Course Objectives A course on algorithms, data structures, and problem solving Learn about algorithm

More information

from Appendix B: Some C Essentials

from Appendix B: Some C Essentials from Appendix B: Some C Essentials tw rev. 22.9.16 If you use or reference these slides or the associated textbook, please cite the original authors work as follows: Toulson, R. & Wilmshurst, T. (2016).

More information

BSM540 Basics of C Language

BSM540 Basics of C Language BSM540 Basics of C Language Chapter 4: Character strings & formatted I/O Prof. Manar Mohaisen Department of EEC Engineering Review of the Precedent Lecture To explain the input/output functions printf()

More information

Basic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

Basic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island Basic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island Data Types Basic Types Enumerated types The type void Derived types

More information

Chapter-14 STRUCTURES

Chapter-14 STRUCTURES Chapter-14 STRUCTURES Introduction: We have seen variables of simple data types, such as float, char, and int. Variables of such types represent one item of information: a height, an amount, a count, and

More information

6.096 Introduction to C++ January (IAP) 2009

6.096 Introduction to C++ January (IAP) 2009 MIT OpenCourseWare http://ocw.mit.edu 6.096 Introduction to C++ January (IAP) 2009 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. Welcome to 6.096 Lecture

More information

Tokens, Expressions and Control Structures

Tokens, Expressions and Control Structures 3 Tokens, Expressions and Control Structures Tokens Keywords Identifiers Data types User-defined types Derived types Symbolic constants Declaration of variables Initialization Reference variables Type

More information

Laboratory 0 Week 0 Advanced Structured Programming An Introduction to Visual Studio and C++

Laboratory 0 Week 0 Advanced Structured Programming An Introduction to Visual Studio and C++ Laboratory 0 Week 0 Advanced Structured Programming An Introduction to Visual Studio and C++ 0.1 Introduction This is a session to familiarize working with the Visual Studio development environment. It

More information

Introduction to C An overview of the programming language C, syntax, data types and input/output

Introduction to C An overview of the programming language C, syntax, data types and input/output Introduction to C An overview of the programming language C, syntax, data types and input/output Teil I. a first C program TU Bergakademie Freiberg INMO M. Brändel 2018-10-23 1 PROGRAMMING LANGUAGE C is

More information

C-LANGUAGE CURRICULAM

C-LANGUAGE CURRICULAM C-LANGUAGE CURRICULAM Duration: 2 Months. 1. Introducing C 1.1 History of C Origin Standardization C-Based Languages 1.2 Strengths and Weaknesses Of C Strengths Weaknesses Effective Use of C 2. C Fundamentals

More information

Presented By : Gaurav Juneja

Presented By : Gaurav Juneja Presented By : Gaurav Juneja Introduction C is a general purpose language which is very closely associated with UNIX for which it was developed in Bell Laboratories. Most of the programs of UNIX are written

More information

MCA Semester 1. MC0061 Computer Programming C Language 4 Credits Assignment: Set 1 (40 Marks)

MCA Semester 1. MC0061 Computer Programming C Language 4 Credits Assignment: Set 1 (40 Marks) Summer 2012 MCA Semester 1 4 Credits Assignment: Set 1 (40 Marks) Q1. Explain the following operators with an example for each: a. Conditional Operators b. Bitwise Operators c. gets() and puts() function

More information

FINAL TERM EXAMINATION SPRING 2010 CS304- OBJECT ORIENTED PROGRAMMING

FINAL TERM EXAMINATION SPRING 2010 CS304- OBJECT ORIENTED PROGRAMMING FINAL TERM EXAMINATION SPRING 2010 CS304- OBJECT ORIENTED PROGRAMMING Question No: 1 ( Marks: 1 ) - Please choose one Classes like TwoDimensionalShape and ThreeDimensionalShape would normally be concrete,

More information

Final CSE 131B Spring 2004

Final CSE 131B Spring 2004 Login name Signature Name Student ID Final CSE 131B Spring 2004 Page 1 Page 2 Page 3 Page 4 Page 5 Page 6 Page 7 Page 8 (25 points) (24 points) (32 points) (24 points) (28 points) (26 points) (22 points)

More information

Arrays and Strings. Antonio Carzaniga. February 23, Faculty of Informatics Università della Svizzera italiana Antonio Carzaniga

Arrays and Strings. Antonio Carzaniga. February 23, Faculty of Informatics Università della Svizzera italiana Antonio Carzaniga Arrays and Strings Antonio Carzaniga Faculty of Informatics Università della Svizzera italiana February 23, 2015 Outline General memory model Definition and use of pointers Invalid pointers and common

More information

공학프로그래밍언어 (PROGRAMMING LANGUAGE FOR ENGINEERS) -STRUCTURE- SPRING 2015 SEON-JU AHN, CNU EE

공학프로그래밍언어 (PROGRAMMING LANGUAGE FOR ENGINEERS) -STRUCTURE- SPRING 2015 SEON-JU AHN, CNU EE 공학프로그래밍언어 (PROGRAMMING LANGUAGE FOR ENGINEERS) -STRUCTURE- SPRING 2015 SEON-JU AHN, CNU EE STRUCTURE Structures are collections of related variables under one name. Structures may contain variables of

More information

Fundamentals of Programming Data Types & Methods

Fundamentals of Programming Data Types & Methods Fundamentals of Programming Data Types & Methods By Budditha Hettige Overview Summary (Previous Lesson) Java Data types Default values Variables Input data from keyboard Display results Methods Operators

More information

Organization of a file

Organization of a file File Handling 1 Storage seen so far All variables stored in memory Problem: the contents of memory are wiped out when the computer is powered off Example: Consider keeping students records 100 students

More information