CSCE 206 Lab Structured Programming in C

Slides:



Advertisements
Similar presentations
Data Structures (Second Part) Lecture 2 : Pointers Bong-Soo Sohn Assistant Professor School of Computer Science and Engineering Chung-Ang University.
Advertisements

Dynamic Memory Allocation (also see pointers lectures) -L. Grewe.
Introduction to Programming Lecture 39. Copy Constructor.
CPT: Pointers/ Computer Programming Techniques Semester 1, 1998 Objective of these slides: –to introduce pointer variables (pointers)
Pointers and Output Parameters. Pointers A pointer contains the address of another memory cell –i.e., it “points to” another variable cost:1024.
CIS 101: Computer Programming and Problem Solving Lecture10 Usman Roshan Department of Computer Science NJIT.
CIS 101: Computer Programming and Problem Solving Lecture 9 Usman Roshan Department of Computer Science NJIT.
Function with Output Parameters 4 We have seen that functions can return a single value or no value (void return type) 4 It is quite often useful to be.
Introduction to C Programming CE
Pointers Example Use int main() { int *x; int y; int z; y = 10; x = &y; y = 11; *x = 12; z = 15; x = &z; *x = 5; z = 8; printf(“%d %d %d\n”, *x, y, z);
ARRAYS In this Lecture, we will try to develop understanding of some of the relatively complex concepts. The following are explained in this lecture with.
Comp 245 Data Structures Linked Lists. An Array Based List Usually is statically allocated; may not use memory efficiently Direct access to data; faster.
7. Pointers, Dynamic Memory 20 th September IIT Kanpur 1C Course, Programming club, Fall 2008.
CSC 2400 Computer Systems I Lecture 5 Pointers and Arrays.
Chapter 7: Pointers Basic concept of pointers Pointer declaration Pointer operator (& and *) Parameter passing by reference.
Problem Solving and Program Design in C (5th Edition) by Jeri R. Hanly and Elliot B. Koffman Chapter 6 (Pointers) © CPCS
Lecture 12: Pointers B Burlingame 25 Nov Announcements Homework 6 due Homework 7 posted, due with the final  Final prep Take home Lab posted tonight.
CSEB 114: PRINCIPLE OF PROGRAMMING Chapter 7: Pointers.
Functions & Pointers in C Jordan Erenrich
Lecture 7 Pointers & Refrence 1. Background 1.1 Variables and Memory  When you declare a variable, the computer associates the variable name with a particular.
Problem Solving and Program Design in C (5th Edition) by Jeri R. Hanly and Elliot B. Koffman CP 202 Chapter 6.
142 L -1 Pointers Chapter 6 C uses a call BY VALUE for functions for example: void add_one(int x, int y) { x=x+1; y=y+1; } int main(void) { int a,b; a=4;
Dr. Yang, QingXiong (with slides borrowed from Dr. Yuen, Joe) LT9: Pointer I CS2311 Computer Programming.
POINTERS IN C. Introduction  A pointer is a variable that holds a memory address  This address is the location of another object (typically another.
Pointer Lecture 2 Course Name: High Level Programming Language Year : 2010.
 Memory setup  Pointer declaration  Address operator  Indirection  Printing addresses or pointers.
POINTERS IN C Pointer Basics, Pointer Arithmetic, Pointer to arrays and Pointer in functions.
UNIT 8 Pointers.
Functions and Pointers Dr. Sajib Datta Oct 6, 2014.
Pointers A variable that holds an address value is called a pointer variable, or simply a pointer.  What is the data type of pointer variables? It’s not.
CSC 215 Pointers and Arrays. Pointers C provides two unary operators, & and *, for manipulating data using pointers The operator &, when applied to a.
Lecture 5 Pointers 1. Variable, memory location, address, value
CS1010 Programming Methodology
CS1010 Programming Methodology
ENEE150 Discussion 04 Section 0101 Adam Wang.
CSE 220 – C Programming Pointers.
BILASPUR UNIVERSITY DEPARTMENT OF COMPUTER SCIENCE AND APPLICATION
Functions and Pointers
Pointers.
Hassan Khosravi / Geoffrey Tien
Lecture 6 C++ Programming
Dynamic Memory Allocation
void Pointers Lesson xx
Functions and Pointers
Basic notes on pointers in C
CSC 253 Lecture 8.
Pointers and Arrays S.Bhuvaneshwari Assistant Professor/CSE
CSC 253 Lecture 8.
Alternate Version of STARTING OUT WITH C++ 4th Edition
CSCE 206 Lab Structured Programming in C
CSCE 206 Lab Structured Programming in C
Pointers Call-by-Reference CSCI 230
CSCE 206 Lab Structured Programming in C
Dynamic Memory A whole heap of fun….
Pointers.
Simulating Reference Parameters in C
7. Pointers, Dynamic Memory
ECE Application Programming
Chien-Chung Shen CIS/UD
C Programming Lecture-8 Pointers and Memory Management
C Programming Pointers
EECE.3220 Data Structures Instructor: Dr. Michael Geiger Spring 2019
Chapter 9: Pointers and String
CSCE 206 Lab Structured Programming in C
CSCE 206 Lab Structured Programming in C
ENERGY 211 / CME 211 Lecture 10 October 13, 2008.
Pointer Arithmetic By Anand George.
CSCE 206 Lab Structured Programming in C
How Memory Leaks Work with Memory Diagram
pointer-to-pointer (double pointer)
Presentation transcript:

CSCE 206 Lab Structured Programming in C Fall 2018 Lecture 6 Ehsanul Haque Nirjhar

Pointer Pointers are variables that stores/points the address of another variables Address refers to the memory location of a variable

Pointer operators & is the address operator. It refers to the address of a variable. * is the dereference operator. It refers to value at a specific address. Why pointer? Call by reference Dynamic Memory Allocation

Pointer int main(void) { int var = 50; int *ptr; ptr=&var; printf("value is %d\n", var); printf("value is %d\n", *ptr); printf("Address of value is %d", ptr); return 0; } Prints: value is 50 Address of value is 1001

Practice Problem-1 Write a program that adds 2 integers using pointer approach. Take 2 integers in 2 variables named a and b. Add those numbers and save it in another variable. Print the address and values of a,b and c.

Practice Problem-2 Write a program that takes 3 integers as input and find the largest number among them. Use pointer variables to do the comparison and output printing.

Practice Problem-3 Write a program that takes 2 integers as input and swap their values. You are required to write a function named SwapValues, that takes 2 pointer variables and within the function swap the values. Print the output from main function.