typedef typedef int Index; typedef char Letter; Index i; i = 17;

Slides:



Advertisements
Similar presentations
Lecture 3 Some commonly used C programming tricks. The system command Project No. 1: A warm-up project.
Advertisements

Programming and Data Structure
Enumeration Data Type enum Day {SUN, MON, TUE, WED, THU, FRI, SAT}; Day today; today = WED; if (today == FRI) cout
Programming in C Pointers and Arrays. 1/14/102 Pointers and Arrays In C, there is a strong relationship between pointers and arrays.In C, there is a strong.
Pointers A pointer is a variable that contains memory address as its value. A variable directly contains a specific value. A pointer contains an address.
Programming in C Pointers and Arrays. 1/14/102 Pointers and Arrays In C, there is a strong relationship between pointers and arrays.In C, there is a strong.
Command line arguments. – main can take two arguments conventionally called argc and argv. – Information regarding command line arguments are passed to.
APS105 Strings. C String storage We have used strings in printf format strings –Ex: printf(“Hello world\n”); “Hello world\n” is a string (of characters)
Define our own data types We can define a new data type by defining a new class: class Student {...}; Class is a structured data type. Can we define our.
Pointers. What is pointer l Everything stored in a computer program has a memory address. This is especially true of variables. char c=‘y’; int i=2; According.
 2007 Pearson Education, Inc. All rights reserved. 1 C Pointers Chapter 7 from “C How to Program" Another ref:
Data Structure and c K.S.Prabhu Lecturer All Deaf Educational Technology.
Fall 2004CS-183 Dr. Mark L. Hornick 1 C++ Arrays C++ (like Java) supports the concept of collections – mechanisms to sort and manipulate many instances.
1 Chapter 15-1 Pointers, Dynamic Data, and Reference Types Dale/Weems.
Chapter 6. Character String Types It is one in which the values consists of sequences of characters. How to Define a variable contain a string? In a programming.
What do I need to Know For My Assignment?. C Pointer Review To declare a pointer, we use the * operator. This is similar to but different from using *
C Tutorial - Pointers CS 537 – Introduction to Operating Systems.
Enumeration Types Managing Ordered Sets. Enumeration types are designed to increase the readability of programs Used to define a set of named constants.
Pointers to pointers & multi-dimensional arrays
LESSON 06.
Pointers & Arrays 1-d arrays & pointers 2-d arrays & pointers.
A bit of C programming Lecture 3 Uli Raich.
Operators And Expressions
Characters and Strings
Lecture 8 String 1. Concept of strings String and pointers
Command Line Arguments
Command line arguments
Command Line Arguments
Learning Objectives Pointers Pointer in function call
CSE 303 Concepts and Tools for Software Development
Command-Line Arguments
Instructor: Ioannis A. Vetsikas
Chapter 7 from “C How to Program"
11/10/2018.
C: Primer and Advanced Topics
Command Line Arguments
Computer Science 210 Computer Organization
CS111 Computer Programming
C Stuff CS 2308.
Chapter 15 Pointers, Dynamic Data, and Reference Types
Enumeration Data Type enum Day {SUN, MON, TUE, WED, THU, FRI, SAT};
MON TUE WED THU
Arrays and Pointers Reference: Chapter , 4.11 CMSC 202.
Chapter 15 Pointers, Dynamic Data, and Reference Types
Programming in C Miscellaneous Topics.
Chapter 1: Introduction to Data Structures(8M)
Introduction to Problem Solving and Programming
Programming in C Miscellaneous Topics.
5.1 Introduction Pointers Powerful, but difficult to master
2008 Calendar.
Homework Starting K&R Chapter 5 Good tutorial on pointers
Sun Mon Tue Wed Thu Fri Sat
C++ Pointers and Strings
ECE 103 Engineering Programming Chapter 51 Random Numbers
ECE 103 Engineering Programming Chapter 46 argc, argv, envp
Introduction to Programming
CS 240 – Lecture 7 Boolean Operations, Increment and Decrement Operators, Constant Types, enum Types, Precedence.
Sun Mon Tue Wed Thu Fri Sat
Chapter 9: Pointers and String
Programming in C Pointers and Arrays.
Strings #include <stdio.h>
C Programming - Lecture 5
1/○~1/○ weekly schedule MON TUE WED THU FRI SAT SUN MEMO
2016 | 10 OCT SUN MON TUE WED THU FRI SAT
Characters and Strings
Sun Mon Tue Wed Thu Fri Sat
C++ Pointers and Strings
Pointers.
C Pointers Another ref:
2008 Calendar.
Presentation transcript:

typedef typedef int Index; typedef char Letter; Index i; i = 17; Letter a = 'A';

enum Type Allows to enumerate values enum Weekday { SUN, MON, TUE, WED, THURS, FRI, SAT }; enum Weekday today; today = MON; if ( today == MON | | today == WED ){ printf ( "Today is cs0449 lecture \n"); }

Chapter 7 from “C How to Program" Pointers Chapter 7 from “C How to Program" Another ref: http://pw1.netcom.com/~tjensen/ptr/pointers.htm

Assignment revisited X = 17; lvalue = rvalue lvalue: expression that evaluates to a location rvalue: expression that evaluates to a value

Simple Pointers Pointer is a value that points to a location in the memory Pointer is associated with a type int number ; int * ptr_to_num ; number = 23; ptr_to_num = & number; printf("Value is %d \n", (*ptr_to_num) ); 23 number 003F45A8 ptr_to_num

More Pointers int number ; int * p1, * p2; p1 = & number ; printf(" *p1 = %d *p2 = %d ", *p1, *p2); /* Output ?? */ number p1 p2

Pointers and Arrays char str[32]; char *ptr; ptr = str ; strcpy( str, "test" ); strcpy( ptr, "test" ); /* does the same as above */

Pointers and Arrays int table [8]; int *ptr ; ptr = table ; How about ptr = & table[0]?? vs. ptr=table;?? 94 table ptr ( ptr + 4 )

Pointer operations Can add and subtract numbers (like array indices) Can increment and decrement! char str[] = "Test"; char * p ; int i; for( p = str, i=0; *p != '\0'; p++, i++); printf(" The length of the string is %d ", i);

NULL pointer A way to tell that pointer points to nothing void main() { char *msg = NULL; MyPrint( msg ); } void MyPrint( char * txt ) if ( txt == NULL ) printf( "Invalid parameters: NULL pointer received\n"); else printf( "%s\n", txt );

Command Line Arguments /* MyProg.c */ int main ( int argc , char *argv[] ) { ... > myProg one two three argc = 4 argv[0] = "myProg" argv[1] = "one" argv[2] = "two" argv[3] = "three“ argv[4] = NULL