Surviving C and PostgreSQL CS186 Supplemental Session 9/13/04 Matt Denny, Paul Huang, Murali Rangan (Originally prepared by Shariq Rizvi, Wei Xu, Shawn.

Slides:



Advertisements
Similar presentations
IT 325 OPERATING SYSTEM C programming language. Why use C instead of Java Intermediate-level language:  Low-level features like bit operations  High-level.
Advertisements

Introduction to Programming Lecture 39. Copy Constructor.
MPI and C-Language Seminars Seminar Plan (1/3)  Aim: Introduce the ‘C’ Programming Language.  Plan to cover: Basic C, and programming techniques.
This Time Pointers (declaration and operations) Passing Pointers to Functions Const Pointers Bubble Sort Using Pass-by-Reference Pointer Arithmetic Arrays.
Pointer, malloc and realloc 1. Name entered was 6 char, not enough space to put null terminator 2 Array of char.
CSCI 171 Presentation 11 Pointers. Pointer Basics.
Growing Arrays in C By: Victoria Tielebein CS 265- Spring 2011.
Informática II Prof. Dr. Gustavo Patiño MJ
Engineering Problem Solving With C++ An Object Based Approach Chapter 9 Pointers and Creating Data Structures.
1 Day 03 Introduction to C. 2 Memory layout and addresses r s int x = 5, y = 10; float f = 12.5, g = 9.8; char c = ‘r’, d = ‘s’;
ECE 353: Lab C Pointers and Structs. Basics A pointer holds an address to some variable Notation: – Dereferencing operator: * int *x is a declaration.
CSSE 332 Functions, Pointers in C. 2 Functions - why and how ? If a problem is large If a problem is large Modularization – easier to: Modularization.
Pointers Discussion 5 Section Housekeeping HW 1 Issues Array Issues Exam 1 Questions? Submitting on Time!
Pointer. Warning! Dangerous Curves C (and C++) have just about the most powerful, flexible and dangerous pointers in the world. –Most other languages.
Informationsteknologi Monday, September 10, 2007Computer Systems/Operating Systems - Class 31 Today’s class Review of more C Operating system overview.
Declaring Arrays Declare an array of 10 elements: int nums[10]; Best practice: #define SIZE 10 int nums[SIZE]; // cannot be int[SIZE] nums; C99: int nums[someVariable]
CS 61C L03 C Arrays (1) A Carle, Summer 2005 © UCB inst.eecs.berkeley.edu/~cs61c/su05 CS61C : Machine Structures Lecture #3: C Pointers & Arrays
CS 61C L03 C Pointers (1)Garcia / Patterson Fall 2002 © UCB CS61C - Machine Structures Lecture 3 C pointers  Dan Garcia (
C pointers (Reek, Ch. 6) 1CS 3090: Safety Critical Programming in C.
Pointers Mark Hennessy Dept. Computer Science NUI Maynooth C++ Workshop 18 th – 22 nd September 2006.
1 Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation –The new operator –The delete operator –Dynamic.
1 Procedural Concept The main program coordinates calls to procedures and hands over appropriate data as parameters.
Arrays and Pointers in C Alan L. Cox
Pointers CSE 2451 Rong Shi.
Prof. amr Goneid, AUC1 CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 10. Pointers & Dynamic Data Structures.
Pointers CS362. Pointers A Pointer is a variable that can hold a memory address Pointers can be used to: Indirectly reference existing variables (sometimes.
Computer Science and Software Engineering University of Wisconsin - Platteville 2. Pointer Yan Shi CS/SE2630 Lecture Notes.
1 Pointers and Arrays. 2 When an array is declared,  The compiler allocates sufficient amount of storage to contain all the elements of the array in.
1 Pointers Arrays have a disadvantage: Their size must be known at compile time. We would like the capability to allocate an array-like object of any needed.
SPL – Practical Session 2 Topics: – C++ Memory Management – Pointers.
C++ Data Types Structured array struct union class Address pointer reference Simple IntegralFloating char short int long enum float double long double.
Prachi A. Joshi Assistant Professor in CSE DIEMS,Aurangabad Unit 1 : Basic Concepts Pointers and dynamic memory allocation, Algorithm Specification, Data.
Copyright 2005, The Ohio State University 1 Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation.
C Lab 1 Introduction to C. Basics of C Developed by Dennis Ritchie in the 1970s. Maps very easily to machine instructions. Even allows inline assembly!
Lecture 6 C++ Programming Arne Kutzner Hanyang University / Seoul Korea.
Pointers *, &, array similarities, functions, sizeof.
Computer Organization and Design Pointers, Arrays and Strings in C Montek Singh Sep 18, 2015 Lab 5 supplement.
System Programming Practical Session 7 C++ Memory Handling.
Pointers in C++. Topics Covered  Introduction to Pointers  Pointers and arrays  Character Pointers, Arrays and Strings  Examples.
1 Object-Oriented Programming Using C++ A tutorial for pointers.
1 Recall that... char str [ 8 ]; str is the base address of the array. We say str is a pointer because its value is an address. It is a pointer constant.
1 Chapter 15-1 Pointers, Dynamic Data, and Reference Types Dale/Weems.
Dr. Yang, QingXiong (with slides borrowed from Dr. Yuen, Joe) LT:10 Advance Pointer Array, String and Dynamic Memory Allocation CS2311 Computer Programming.
UNIT 8 Pointers.
C Tutorial - Pointers CS 537 – Introduction to Operating Systems.
“Success consists of going from failure to failure without loss of enthusiasm.” Winston Churchill.
Pointers: Basics. 2 Address vs. Value Each memory cell has an address associated with it
Windows Programming Lecture 03. Pointers and Arrays.
1 Memory, Arrays & Pointers. Memory 2 int main() { char c; int i,j; double x; cijx.
Basic Concepts:- Invalid use of Address Operator &75 &(‘a’) &(a+b)
Pointers Pointers are variables that contain memory addresses as their values. A variable directly contains a specific value. A pointer contains an address.
1 Memory, Arrays & Pointers. Memory 2 int main() { char c; int i,j; double x; cijx.
Overview Working directly with memory locations is beneficial. In C, pointers allow you to: change values passed as arguments to functions work directly.
Intro to Pointers in C CSSE 332 Operating Systems
CS1010 Programming Methodology
Computer Organization and Design Pointers, Arrays and Strings in C
Day 03 Introduction to C.
Day 03 Introduction to C.
Lecture 6 C++ Programming
Andy Wang Object Oriented Programming in C++ COP 3330
Pointers, Dynamic Data, and Reference Types
Outline Defining and using Pointers Operations on pointers
Pointers The C programming language gives us the ability to directly manipulate the contents of memory addresses via pointers. Unfortunately, this power.
5.1 Introduction Pointers Powerful, but difficult to master
CS111 Computer Programming
C++ Pointers and Strings
C Programming Lecture-8 Pointers and Memory Management
C++ Pointers and Strings
Pointers, Dynamic Data, and Reference Types
Introduction to C CS 3410.
Presentation transcript:

Surviving C and PostgreSQL CS186 Supplemental Session 9/13/04 Matt Denny, Paul Huang, Murali Rangan (Originally prepared by Shariq Rizvi, Wei Xu, Shawn Jeffery)

Outline A Review of C PostgreSQL Basics Tour of Assignment 1 2Q

A Review of C Review Pitfalls of C Programming for Java Programmers Pointers and Arrays Strings Segmentation Faults For more information, consult “ The C Programming Language” by Kernighan and Ritchie or tutorial on web site

Pointer = variable containing address of another variable float f; /* data variable */ float *f_addr; /* pointer variable */ f_addr = &f; /* & = address operator */ ?? f f_addr ? any float any address ?4300 f f_addr

*f_addr = 3.2; /* indirection operator */ float g=*f_addr; /* indirection:g is now 3.2 */ f = 1.3; f f_addr f f_addr

int month[12]; /* month is a pointer to base address 430: system allocates 12*sizeof(int) bytes at 430 */ month[3] = 7; /* integer at address (430+3*sizeof(int)) is now 7 */ ptr = month + 2; /* ptr points to month[2], i.e. ptr =(430+2 * sizeof(int)) = 438 */ ptr[5] = 12; /* int at address (434+5*sizeof(int)) is now 12; same as month[7] */ Arrays and Pointers Now, month[6], *(month+6), (month+4)[2], ptr[4], *(ptr+4) are all the same integer variable.

Strings #include main() { char msg[10]; /* array of 10 chars */ char *p; /* pointer to a char */ char msg2[]=“Hello”; /* msg2 = ‘H’’e’’l’’l’’o’’\0’ */ msg = “Bonjour”; /* ERROR. msg has a const address. Think of space allocation*/ p = “Bonjour”; /* address of “Bonjour” goes into p */ p = msg; /* OK */ p[0] = ‘H’, p[1] = ‘i’,p[2]=‘\0’; /* *p and msg are now “Hi” Warning: be careful if you have space allocated for p!!*/ }

Segmentation Fault? You reference memory that the OS doesn’t want you to What to check? Dereferencing a null pointer 99% –Output or trace with a debugger –Check array bounds