Programming in C. Week Tiina Niklander. Faculty of Science

Size: px
Start display at page:

Download "Programming in C. Week Tiina Niklander. Faculty of Science"

Transcription

1 Programming in C Week Tiina Niklander Faculty of Science Department of Computer Science

2 Meeting structure First week Some notes Second week Focus on pointers Slides related to first week topics covered if time allows or some questions arise Faculty of Science Department of Computer Science

3 First week tasks TMC problems Difficulties configuring NetBeans properly Submission failed occasionally, Some tasks did not succeed locally, but were correct on the server Tasks Uninitialized values: test failure information not useful Printf: formatting problems, especially \n Faculty of Science Department of Computer Science

4 Feedback Math.h use the functions for mathematical tasks -> less errors ceil andfabs should have been used in 1.2 various sums Study the material, not just trial-and-error from book, man pages Printf and scanf see next slide Faculty of Science Department of Computer Science

5 /* Program that reads two integer values, and * outputs the maximum of these values. */ #include <stdio.h> int main() { int i, j; printf("enter two integers:"); if(scanf("%d%d", &i, &j)!= 2) { fprintf(stderr, "wrong input\n"); return EXIT_FAILURE; printf("maximum of %d and %d is %d\n", return EXIT_SUCCESS; i, j, i > j? i : j); Read two values Conditional operation

6 Briefly about pointers char *p; /* pointer to a character or string */ int *q; /* pointer to one integer (or array) */ /*Memory allocated only for the pointer! */ 345 : Main memory Memory block char *p = This string is allocated ; int numbers[] = {1, 2, 3, 4, 5; double table[100]; Allocate memory for the array and set the pointer to the array. (No memory allocated for array name! constant pointer only allocates the memory block containing the values!) 678 : pointer p 680 : 915 : pointer q 740 : 830 : Program code function foo1 function foo2 Faculty of Science Department of Computer Science

7 Pointers (and arrays) Array is just a sequence of values with a joint name. int a[15] is sequence of 15 integers. Array name is treated as a pointer, whose value is the address of the first element in the sequence. pa = &a[0] pa = a pointer arithmetic allows operations on array elements *(pa +3) is the same as a[3] pa+3 is the same as &a[3] Faculty of Science Department of Computer Science

8 Pointer arithmetics and operations Remember: NULL p = &c c = *p c = **r p = q address of c value of the address pointed by p - - (two jumps ) allowed when p and q of same type p+i, p-i p is array, i has to be integer with suitable value p-q, p and q pointers of the same array and q<p p < q, p == q *ip++ increments the address by one (*ip)++ increments the value in the address by one Faculty of Science Department of Computer Science

9 Pointer arithmetics p int **p; int *q,*r; 3 i 12 int i; i = **p; q const int *p; q = &i; /* q s new value is i s address int const *p; i = *q+1; i = ++*q; /* i=6*/ const int const *p; i = *q++; /*???? */ r = q; *r = 3; /* i=3 */ char msg [] = It is time ; msg: It is time\0 char *pv = It is time ; It is time\0 void *p; i= *(int*) p; pv Faculty of Science Department of Computer Science

10 Example code int main(int argc, char** argv) { int x=1, y=2, z[10]; int *ip; int *p, q; int *r, *s; ip = &x; y = *ip; /* y = x =1 */ *ip = 0; /* x = 0 */ ip = &z[0]; p is a pointer variable and q is integer variable x y z ip double atof(char * string); Faculty of Science Department of Computer Science Pointers as arguments for functions are very common. (Always used with arrays and needed for call by reference)

11 Memory allocation Explicit memory allocations! malloc static data structures calloc dynamic array realloc change the size of already allocated object free deallocate the memory /* ALWAYS CHECK THE RETURN VALUE!!! */ if (k=malloc(sizeof(double))) error; /* allocation failed, do something else or terminate program */ /* memory allocation succeeded and k is the pointer to the new structure */ Faculty of Science Department of Computer Science

12 Functions: Call by value, call by reference C uses always call by value => function cannot change the value it receives as argument. Call by reference done with pointers!!! void swap(int x, int y) { int apu; apu=x; x=y; y= apu; copies void swap(int *x, int *y) { int apu; apu=*x; *x=*y; *y= apu; Faculty of Science Department of Computer Science x y Addresses of x and y Call: swap (&x, &y); double product (const double block, int size); 3 4 Make sure that function does not change the variable (ANSI standard!)

13 #include <stdio.h> Example code: copy a string - Passing array to a function void copy_string( char *s, char *t) { int i =0; while ( (s[i] = t[i])!= \0 ) i++; Strings (character arrays ending with \0 ) as arguments. C is always passing only the address of the first element of any array. int main (void) Processing one character of each array { char here [] = This string is copied., there[50]; copy_string ( here, there); printf( %s\n, there); copy_string ( there, here); printf( %s\n, there); return 0; Faculty of Science Department of Computer Science

14 Example code: copy a string Now with pointers Version 1: Version 2: void copy_string( char *s, char *t) { while ( (*s = *t)!= \0 ) s++; t++; void copy_string( char *s, char *t) { while ( (*s++ = *t++)!= \0 ) ; Version 3: void copy_string( char *s, char *t) { while ( *s++ = *t++ ) ; NOTE: The function prototype is identical with the previous slide Faculty of Science Department of Computer Science Minimalistic!

15 More about pointers and some good practices Generic pointer (void *p) can be used with type cast to handle a variable of that type. *(double *)p Memory allocation for n integers int *p; if ((p=malloc(n*sizeof(int))) == NULL) error; Memory deallocation: remember to free(p); p=null; i th element of array p[i] (preferred over *(p+i) ) Handling an array p for (pi = p; pi < p+size; pi++) remember to use pointer pi in the loop Faculty of Science Department of Computer Science

16 Still more Call by reference 1. Prototype s argument a pointer void func(int *pp) 2. In the function use the pointed value. *pp 3. In the function call: address of the variable func(&variable); 4. In the function call: pointer func(pointer_variable); Array of struct for (p = block; p < block + n*elsize; p+= elsize) i. element of struct array p = block + i*elsize Faculty of Science Department of Computer Science

17 Evaluation order Preceedence Arithmetical ops { Bitwise moves { Value comparations { Bitwise comparations and or Conditional op Same line - same priority () []. ->! ~ & * (tyyppi) sizeof * / % + - << >> < <= > >= ==!= & ^ &&?: = *= /= %= += -= <<= >>= &=!= ^=,

18 Assosiativity Expression a < b < c is interpreted as (a < b) < c And the meaning is different than expression a < b && b < c

19 Style: using space Do not use space with the following : ->. []! ~ (sign) *(pointer)& Usually have space around these: = +=?: + < && + (addition) and others a->b a[i] *c a = a + 2; a= b+ 1; a = a+b * 2;

20 Constants Defined as variables, but with addition const Usually constant names in capital letters const float PI = ; const int BIG_NUMBER = 0xFF7D; const int TRUE = 1; const int FALSE = 0; const char LETTER_A = a ; const char [] MJONO = String has parenthesis around it ;

21 Macros Preprocessor control textual replacement! Macro is a text that is replaced with other text before the actual compilation NOTE: Rest of the line is the replacement string as it is!! Can be used to define constants but is more powerful #define MAKSIMI 30 #define NAME Tiina Niklander #define TRUE 1 #define FALSE 0

22 Avoid mistakes u i = 8 different than i == 8 u Remember to set initial values to variables! u Check the limits (avoid off by one ) u These are not logical operations!!! e1 & e2 e1 e2 if(x = 1)

23 Overflow NEVER test overflow with i + j > INT_MAX BUT do: i > INT_MAX - j Source: Müldner

24 Struct struct info { char firstname[20]; char lastname[20]; int age; ; struct info i1, i2; typedef struct InfoT { char firstname[20]; char lastname[20]; int age; InfoT; InfoT p1; Preferable alternative! Access to struct field with. notation struct.field: p1.age = 18; printf("%s\n", i2.firstname); struct info { char firstname[20]; char lastname[20]; int age; k1, k2;

25 Pointer to struct Access to struct field: (*p).x or p->x typedef struct pair { double x; double y; PairT, *PairTP; PairT x; PairTP p; PairT w; PairTP q; PairTP p = &w; if((q = malloc(sizeof(pairt))) == NULL) if((q = malloc(sizeof(struct pair))) == NULL) w.x = 2; p->x = 1; (*p).x = 1; *p.x = 1; q->y = 3.5;

26 Linked lists List as abstract data structure: covered in data structures and algorithms course Linked list structural decisions: singly or doubly (traversals to one or two directions) Loop or no-loop (= NULL terminated) Header node or not Ordered or not Unique elements or multiple occurrences of same value

27 Linked List - definitions Header, singly linked No loop = NULL to terminate NOTE: definition of the next field! typedef double DataType; typedef struct elem { DataType value; struct elem *next; ElemT, *ElemTP; typedef struct { ElemTP first; ListT, *ListTP; ListTP p; p first ListT value 2 next ElemT value 3.5 next NULL ElemT

28 Linked list with header: Create and delete Create list Just allocate header node and set its field values Delete list Separate function to remove elements Here just free space of header node ListTP construct(void) { ListTP p; if((p = malloc(sizeof(listt))) == NULL) return NULL; p->first = NULL; return p; void destruct(listtp *this) { clear(*this); /* remove list elements */ free(*this); *this = NULL;

29 Linked list with header: Using it All list operations must maintain the following invariants: For empty list, always p->first == NULL. For non-empty list, always last node s next-field ==NULL. p first ListT p NULL first ListT value 2 next ElemT value 3.5 next ElemT NULL

30 Linked list with header: using it p Operations: List traversal first ListT value 2 next ElemT Always (and only) to the link direction Adding to list Beginning, middle, end Removing from the list Beginning, middle, end value 3.5 next ElemT NULL

31 p List traversal first ListT value 2 next ElemT value 3.5 next ElemT aux void printall(const ListTP this) { ElemTP aux; for(aux=this->first; aux!=null; aux=aux->next) printf("%f\n", aux->value); NULL /* Keep aux in previous node */ If ((p->first!= NULL) && (p->first->next!=null)) for(aux = p->first; aux->next!= NULL; aux = aux->next)...

32 Add to beginning of the list p first ListT value 2 next ElemT value 3.5 next ElemT int insertfront(listtp this, DataType d) { ElemTP aux; if((aux = malloc(sizeof(elemt))) == NULL) return 0; value 2 next ElemT NULL aux->next = this->first; /* save state */ aux->value = d; this->first = aux; return 1;

33 Removing last node int deletelast(listtp this, DataType *value) { ElemTP aux; if(this->first == NULL) /* empty list */ return 0; if(this->first->next == NULL) { /* single */ *value = this->first->value; free(this->first); this->first = NULL; return 1; for(aux = this->first; aux->next->next!= NULL; aux = aux->next) ; /* aux points to second last element */ *value = aux->next->value; free(aux->next); aux->next = NULL; return 1; p first ListT value 2 next ElemT value 3.5 next ElemT NULL

34 Deleting/clearing the whole list Free node by node from beginning to end int deletefirst(listtp this) { ElemTP aux = this->first; if(aux == NULL) /* empty list */ return 0; this->first = aux->next; free(aux); return 1; void clear(listtp this) { while(deletefirst(this)) ; this->first = NULL;

35 Example: ModuleList Own module (list.h and list.c) that can be compiled separately, contains type definitions and functions This module can - Handle multiple separate lists - Data handled by void pointer, so different lists can contain different types of data - Hide the actual implementation details of the list Type definitions: ListItem and List Functions: CreateList, CreateItem, AddTail, AddHead, ListLength, DeleteList, PrintStringList, EmptyList Source: Jan Lindström s (Finnish) lecture material,2000

36 Interface definitions: list.h #ifndef MY_LIST_LIBRARY #define MY_LIST_LIBRARY /* Type definitions*/ typedef struct listitem { struct listitem *Next; /* Pointer to next element */ struct listitem *Prev; /* pointer to previous elem */ void *Data; /* Pointer to data */ unsigned long Size; /* Size of data */ ListItem; typedef struct { /* header node of the list */ ListItem *Head; ListItem *Tail; unsigned long Items; /* number of elements */ List;

37 List.h continues /* Function signatures / interface definitions*/ extern List *CreateList(void); /* Create new list */ extern ListItem *CreateItem(void *Data, unsigned long Size); /* Create new element*/ extern int AddTail(List *,ListItem *); /*Add to end*/ extern int AddHead(List *,ListItem *); /* Add to beginning */ extern unsigned long ListLength(List *); /* Count lenght */ extern void DeleteList(List *); /* Destroy list */ extern void PrintStringList(List *); /* Print the list content, assume strings */ extern int EmptyList(List *); /* Check if list is empty */ #endif

38 List.c : CreateList /* Reserve memory area for the new list and set the fields */ List *CreateList(void) { List *new; if(!(new = (List *)malloc(sizeof(list)))) return NULL; new->head = NULL; new->tail = NULL; new->items = 0; return new;

39 List.c: CreateItem /* Allocate memory for new node and set fields*/ ListItem *CreateItem(void *Data,unsigned long size) { ListItem *uusi; /* If no data, exit and do not create a node*/ if (Data == NULL) return NULL; if(!(uusi = (ListItem *)malloc(sizeof(listitem)))) return NULL; if(!(uusi->data = (void *)malloc(size))) return NULL; uusi->next = NULL; uusi->prev = NULL; memcpy(uusi->data,data,size); uusi->size = size; return uusi;

40 List.c: AddTail /* Add to the end of the list*/ extern int AddTail(List *lista,listitem *item) { if (lista == NULL item == NULL ) return 1; if ( lista->head == NULL) lista->head = lista->tail = item; else { lista->tail->next = item; item->prev = lista->tail; lista->tail = item; lista->items++; return 0;

41 List.c: AddHead /* Add to the head of the list*/ extern int AddHead(List *lista,listitem *item) { if (lista == NULL item == NULL ) return 1; if ( lista->head == NULL) lista->head = lista->tail = item; else { lista->head->prev = item; item->next = lista->head; lista->head = item; lista->items++; return 0;

42 List.c: ListLength ja EmptyList /* Count' list length */ unsigned long ListLength(List *lista) { if ( lista == NULL ) return 0; else return lista->items; /* Check if list is empty */ int EmptyList(List *lista) { if ( lista == NULL) return 1; else if (lista->head == NULL ) return 1; else

43 List.c:DeleteList /* Destroy the whole list*/ void DeleteList(List *lista) { ListItem *tmp; if ( lista == NULL ) return; tmp = lista->head; while(tmp!= NULL) { tmp = lista->head->next; free(lista->head->data); free(lista->head); lista->head = tmp; free(lista);

44 List.c: PrintStringList /* Print the whole list */ void PrintStringList(List *lista) { ListItem *tmp = lista->head; printf(" "); while(tmp!= NULL) { printf("%s ",(char *)tmp->data); tmp = tmp->next; printf(" -\n"); Here assumes that list contains strings. More generic solutions would be to use function parameter to handle data. Caller would then provide function to handle data elements and the print function would be more general.

45 Slides related to first week Faculty of Science Department of Computer Science

46 Simple types Int 28, 074, 0x2A char, one character, actually a numerical value, do not assume anything a \065 \xa6 float, double NOTE: no boolean - Use integer values FALSE and all other values TRUE Size of these not fixed between systems (see: sizeof or limits.h) signed, unsigned unsigned int signed char short, long long char short int Combined signed short int unsigned long int

47 Header file: limits.h #include <limits.h> Limits.h contains the maximum and minimum values of different types in this environment At department the file is in /usr/include/ Always: INT_MAX >= Lots of values: eg. SHRT_MAX (signed short) With ints you can define the type after value (U, L) 12U is unsigned int and 7L long int sizeof(short) <= sizeof(int) <= sizeof(long)

48 Header file: float.h #include <float.h> Contains size and limit values for - float - double - long double sizeof(float) <= sizeof(double) <= sizeof(long double)

49 Type conversion Implicit: operands with different types -> automatic type conversion for the arithmetic operation using the better quality type: int, char unsigned long unsigned long float double long double Explicit: (double)int_var; (int) letter;

50 Statements Conditional Loops if (cond) statement; else statement; If (cond) { statements else{ statements for (;;) statement while (1) { statements do{ statements while (cond); Interrupting a loop Break - continue from the statement AFTER the loop Continue continue with NEXT ROUND Not named!!

51 Using break While (1) { printf( give two numbers a and b, a < b: ); if (scanf( %d%d, &a, &b) == 2) break; if (a < b) break;... /* break continues from here */ Several typical C features - eternal loop while(1) - error checks!! - standard functions

52 Exiting from a deep loop structure Exit over multiple loop levels must be done with goto (Avoid using for anything else!) for(i = 0; i < length; i++) for(j = 0; j < length1; j++) if(f(i, j) == 0) goto done; done: Break would continue the outer loop!

53 switch.. /* Beginning of main and variable definitions */ Printf( Please give at most %d chars\n, LIMIT); For (i = 1; i <= LIMIT; i++) { if ( (c=getchar()) == EOF) break; /* end of file with CTRL-D */ switch (c) { case : space++; break; case \t : tabul++; break; case * : asterisk++; break; default : if (c>= a && c<= z ) lowercaseletters++;... /* continues e.g. with printing */

54 Control Statements This loop while(expr!= 0) statement; Is identical with this one while(expr) statement;

55 while(1) { Read characters until sentinel if((aux = getchar()) == EOF aux == SENTINEL)... or: while(1) { break; if((aux = getchar()) == EOF) break; if(aux == SENTINEL)... break;

56 Read integers while(1) { if (scanf("%d", &i)!= 1 i == SENTINEL) break;

57 Input and output briefly Character at a time int getchar() int putchar(int) Formatted int scanf("format", &var) int printf("format", exp)

58 /* File: ex1.c * Program that reads a single character and * outputs it, followed by end-of-line */ #include <stdio.h> #include <stdlib.h> int main() { NOTE: These header files are needed for the standard functions used int c; /* chars must be read as ints */ if ((c = getchar()) == EOF) return EXIT_FAILURE; putchar(c); putchar('\n'); return EXIT_SUCCESS;

59 Printf & scanf: integer values d signed decimal ld long decimal u unsigned decimal o octal x, X hexadecimal printf("%d%o%x", 17, 18, 19);

60 Printf and scanf: real number, floating point numbers f e default is 6 digits: [-] ddd.ddd [-] d.ddddde{signdd E [-] d.ddddde{signdd g fe (f, e only if needed (e.g. sign <-4)) G FE printf("%5.3f\n", ); printf("%5.3e\n", ); e+02

61 Printf and scanf: chars and string c one character s string printf("%c", 'a'); printf("%d", 'a'); printf("this %s test", "is");

62 scanf() return value scanf() returns as its value the number of read items and EOF, if not item was read before the end-of-file occured For example scanf("%d%d", &i, &j) may return: 2 If both values were read correctly 1 If only i was read 0 If reading failed completely EOF if file ended.

63 scanf scanf ( %c,c); or scanf ( %c, c); What is the difference in behaviour? Why do you use the space in the beginning of the format string? Faculty of Science Department of Computer Science

Programming in C. Lecture Tiina Niklander. Faculty of Science

Programming in C. Lecture Tiina Niklander. Faculty of Science Programming in C Lecture 3 17.9.2018 Tiina Niklander Faculty of Science Department of Computer Science 17.9.2018 1 Week 2 covers Pointer basics operators and address arithmetics as function argument Precedence

More information

Member Access through Pointer. The next lecture is on Tue, in Auditorio : Structures and Functions.

Member Access through Pointer. The next lecture is on Tue, in Auditorio : Structures and Functions. Member Access through Pointer The next lecture is on Tue, 26.11 in Auditorio 12-14 If p is a pointer to a structure that has a member w, then p->w gives access to w. Memory Allocation for a Structure For

More information

Fundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University

Fundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University Fundamental Data Types CSE 130: Introduction to Programming in C Stony Brook University Program Organization in C The C System C consists of several parts: The C language The preprocessor The compiler

More information

Should we delete all the files? (Example) From last lecture: Why use a file at all? Asst 1a. Assignment 1. Sample code.

Should we delete all the files? (Example) From last lecture: Why use a file at all? Asst 1a. Assignment 1. Sample code. From last lecture: Why use a file at all? Put the temporary result in a variable? x=`date` But, grep only works with files! if date grep Mon > /dev/null then echo Another week starts. fi Should we delete

More information

Kurt Schmidt. October 30, 2018

Kurt Schmidt. October 30, 2018 to Structs Dept. of Computer Science, Drexel University October 30, 2018 Array Objectives to Structs Intended audience: Student who has working knowledge of Python To gain some experience with a statically-typed

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

Writing an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and

Writing an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and Writing an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and #include The Use of printf() and scanf() The Use of printf()

More information

THE FUNDAMENTAL DATA TYPES

THE FUNDAMENTAL DATA TYPES THE FUNDAMENTAL DATA TYPES Declarations, Expressions, and Assignments Variables and constants are the objects that a prog. manipulates. All variables must be declared before they can be used. #include

More information

A Fast Review of C Essentials Part I

A Fast Review of C Essentials Part I A Fast Review of C Essentials Part I Structural Programming by Z. Cihan TAYSI Outline Program development C Essentials Functions Variables & constants Names Formatting Comments Preprocessor Data types

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

Procedural programming with C

Procedural programming with C Procedural programming with C Dr. C. Constantinides Department of Computer Science and Software Engineering Concordia University Montreal, Canada August 11, 2016 1 / 77 Functions Similarly to its mathematical

More information

A. Year / Module Semester Subject Topic 2016 / V 2 PCD Pointers, Preprocessors, DS

A. Year / Module Semester Subject Topic 2016 / V 2 PCD Pointers, Preprocessors, DS Syllabus: Pointers and Preprocessors: Pointers and address, pointers and functions (call by reference) arguments, pointers and arrays, address arithmetic, character pointer and functions, pointers to pointer,initialization

More information

CSCI 171 Chapter Outlines

CSCI 171 Chapter Outlines Contents CSCI 171 Chapter 1 Overview... 2 CSCI 171 Chapter 2 Programming Components... 3 CSCI 171 Chapter 3 (Sections 1 4) Selection Structures... 5 CSCI 171 Chapter 3 (Sections 5 & 6) Iteration Structures

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

Tutorial 1: Introduction to C Computer Architecture and Systems Programming ( )

Tutorial 1: Introduction to C Computer Architecture and Systems Programming ( ) Systems Group Department of Computer Science ETH Zürich Tutorial 1: Introduction to C Computer Architecture and Systems Programming (252-0061-00) Herbstsemester 2012 Goal Quick introduction to C Enough

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

C Review. MaxMSP Developers Workshop Summer 2009 CNMAT

C Review. MaxMSP Developers Workshop Summer 2009 CNMAT C Review MaxMSP Developers Workshop Summer 2009 CNMAT C Syntax Program control (loops, branches): Function calls Math: +, -, *, /, ++, -- Variables, types, structures, assignment Pointers and memory (***

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

Programming in C Lecture 6

Programming in C Lecture 6 Programming in C Lecture 6 8.10.2018 Tiina Niklander Department of Computer Science www.cs.helsinki.fi 8.10.2018 1 Week 5 covers Macros Parameterized macros on this lecture Function pointers Void and void

More information

Programming. Elementary Concepts

Programming. Elementary Concepts Programming Elementary Concepts Summary } C Language Basic Concepts } Comments, Preprocessor, Main } Key Definitions } Datatypes } Variables } Constants } Operators } Conditional expressions } Type conversions

More information

Fundamental of Programming (C)

Fundamental of Programming (C) Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 9 Pointer Department of Computer Engineering 1/46 Outline Defining and using Pointers

More information

Dynamic memory allocation (malloc)

Dynamic memory allocation (malloc) 1 Plan for today Quick review of previous lecture Array of pointers Command line arguments Dynamic memory allocation (malloc) Structures (Ch 6) Input and Output (Ch 7) 1 Pointers K&R Ch 5 Basics: Declaration

More information

Fundamental of Programming (C)

Fundamental of Programming (C) Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 3 Constants, Variables, Data Types, And Operations Department of Computer Engineering

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

ECE 264 Exam 2. 6:30-7:30PM, March 9, You must sign here. Otherwise you will receive a 1-point penalty.

ECE 264 Exam 2. 6:30-7:30PM, March 9, You must sign here. Otherwise you will receive a 1-point penalty. ECE 264 Exam 2 6:30-7:30PM, March 9, 2011 I certify that I will not receive nor provide aid to any other student for this exam. Signature: You must sign here. Otherwise you will receive a 1-point penalty.

More information

Introduction to C. Systems Programming Concepts

Introduction to C. Systems Programming Concepts Introduction to C Systems Programming Concepts Introduction to C A simple C Program Variable Declarations printf ( ) Compiling and Running a C Program Sizeof Program #include What is True in C? if example

More information

Basic Types and Formatted I/O

Basic Types and Formatted I/O Basic Types and Formatted I/O C Variables Names (1) Variable Names Names may contain letters, digits and underscores The first character must be a letter or an underscore. the underscore can be used but

More information

Data Type Fall 2014 Jinkyu Jeong

Data Type Fall 2014 Jinkyu Jeong Data Type Fall 2014 Jinkyu Jeong (jinkyu@skku.edu) 1 Syntax Rules Recap. keywords break double if sizeof void case else int static... Identifiers not#me scanf 123th printf _id so_am_i gedd007 Constants

More information

cs3157: another C lecture (mon-21-feb-2005) C pre-processor (3).

cs3157: another C lecture (mon-21-feb-2005) C pre-processor (3). cs3157: another C lecture (mon-21-feb-2005) C pre-processor (1). today: C pre-processor command-line arguments more on data types and operators: booleans in C logical and bitwise operators type conversion

More information

Pointers and File Handling

Pointers and File Handling 1 Pointers and File Handling From variables to their addresses Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR 2 Basics of Pointers INDIAN INSTITUTE OF TECHNOLOGY

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

Fundamentals of Programming

Fundamentals of Programming Fundamentals of Programming Lecture 3 - Constants, Variables, Data Types, And Operations Lecturer : Ebrahim Jahandar Borrowed from lecturer notes by Omid Jafarinezhad Outline C Program Data types Variables

More information

BLM2031 Structured Programming. Zeyneb KURT

BLM2031 Structured Programming. Zeyneb KURT BLM2031 Structured Programming Zeyneb KURT 1 Contact Contact info office : D-219 e-mail zeynebkurt@gmail.com, zeyneb@ce.yildiz.edu.tr When to contact e-mail first, take an appointment What to expect help

More information

Computers Programming Course 5. Iulian Năstac

Computers Programming Course 5. Iulian Năstac Computers Programming Course 5 Iulian Năstac Recap from previous course Classification of the programming languages High level (Ada, Pascal, Fortran, etc.) programming languages with strong abstraction

More information

LESSON 5 FUNDAMENTAL DATA TYPES. char short int long unsigned char unsigned short unsigned unsigned long

LESSON 5 FUNDAMENTAL DATA TYPES. char short int long unsigned char unsigned short unsigned unsigned long LESSON 5 ARITHMETIC DATA PROCESSING The arithmetic data types are the fundamental data types of the C language. They are called "arithmetic" because operations such as addition and multiplication can be

More information

C: Pointers, Arrays, and strings. Department of Computer Science College of Engineering Boise State University. August 25, /36

C: Pointers, Arrays, and strings. Department of Computer Science College of Engineering Boise State University. August 25, /36 Department of Computer Science College of Engineering Boise State University August 25, 2017 1/36 Pointers and Arrays A pointer is a variable that stores the address of another variable. Pointers are similar

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

Number Systems, Scalar Types, and Input and Output

Number Systems, Scalar Types, and Input and Output Number Systems, Scalar Types, and Input and Output Outline: Binary, Octal, Hexadecimal, and Decimal Numbers Character Set Comments Declaration Data Types and Constants Integral Data Types Floating-Point

More information

CS3157: Advanced Programming. Outline

CS3157: Advanced Programming. Outline CS3157: Advanced Programming Lecture #8 Feb 27 Shlomo Hershkop shlomo@cs.columbia.edu 1 Outline More c Preprocessor Bitwise operations Character handling Math/random Review for midterm Reading: k&r ch

More information

Programming in C Lecture Tiina Niklander

Programming in C Lecture Tiina Niklander Programming in C Lecture 5 1.10.2018 Tiina Niklander Liisa Marttinen & Tiina Niklander www.cs.helsinki.fi C programming 2016 1 Week 4 covers Multidimensional arrays Pointer arrays Command-line arguments

More information

CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community

CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community http://csc.cs.rit.edu History and Evolution of Programming Languages 1. Explain the relationship between machine

More information

Data types, variables, constants

Data types, variables, constants Data types, variables, constants 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 in C 2.6 Decision

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

Programming in C week 1 meeting Tiina Niklander

Programming in C week 1 meeting Tiina Niklander Programming in C week 1 meeting 2.9.2015 Tiina Niklander Faculty of Science Department of Computer Science 3.9.2015 1 Course structure Based on C programming course in Aalto, but with some exercises created

More information

SOFTWARE Ph.D. Qualifying Exam Fall 2017

SOFTWARE Ph.D. Qualifying Exam Fall 2017 (i) (4 pts.) SOFTWARE Ph.D. Qualifying Exam Fall 2017 Consider the following C program. #include #define START 2 #define LIMIT 60 #define STEP 7 #define SIZE 3 int main(void) { int i = START,

More information

C Programming Language (Chapter 2 of K&R) Variables and Constants

C Programming Language (Chapter 2 of K&R) Variables and Constants C Programming Language (Chapter 2 of K&R) Types, Operators and Expressions Variables and Constants Basic objects manipulated by programs Declare before use: type var1, var2, int x, y, _X, x11, buffer;

More information

CS 61C: Great Ideas in Computer Architecture Introduction to C

CS 61C: Great Ideas in Computer Architecture Introduction to C CS 61C: Great Ideas in Computer Architecture Introduction to C Instructors: Vladimir Stojanovic & Nicholas Weaver http://inst.eecs.berkeley.edu/~cs61c/ 1 Agenda C vs. Java vs. Python Quick Start Introduction

More information

Approximately a Test II CPSC 206

Approximately a Test II CPSC 206 Approximately a Test II CPSC 206 Sometime in history based on Kelly and Pohl Last name, First Name Last 5 digits of ID Write your section number(s): All parts of this exam are required unless plainly and

More information

int main(void) { int a, b, c; /* declaration */

int main(void) { int a, b, c; /* declaration */ &KDSWHULQ$%& #include int main(void) { int a, b, c; /* declaration */ float x, y=3.3, z=-7.7; /* declaration with initialization */ printf("input two integers: "); /* function call */ scanf("%d%d",

More information

Programming in C First meeting

Programming in C First meeting Programming in C First meeting 8.9.2016 Tiina Niklander Faculty of Science Department of Computer Science www.cs.helsinki.fi 8.9.2016 1 Course structure Weekly exercise deadline on Wednesday, lectures

More information

Lectures 5-6: Introduction to C

Lectures 5-6: Introduction to C Lectures 5-6: Introduction to C Motivation: C is both a high and a low-level language Very useful for systems programming Faster than Java This intro assumes knowledge of Java Focus is on differences Most

More information

3. Types of Algorithmic and Program Instructions

3. Types of Algorithmic and Program Instructions 3. Types of Algorithmic and Program Instructions Objectives 1. Introduce programming language concepts of variables, constants and their data types 2. Introduce types of algorithmic and program instructions

More information

19-Nov CSCI 2132 Software Development Lecture 29: Linked Lists. Faculty of Computer Science, Dalhousie University Heap (Free Store)

19-Nov CSCI 2132 Software Development Lecture 29: Linked Lists. Faculty of Computer Science, Dalhousie University Heap (Free Store) Lecture 29 p.1 Faculty of Computer Science, Dalhousie University CSCI 2132 Software Development Lecture 29: Linked Lists 19-Nov-2018 Location: Chemistry 125 Time: 12:35 13:25 Instructor: Vlado Keselj Previous

More information

Programming in C First meeting Tiina Niklander

Programming in C First meeting Tiina Niklander Programming in C First meeting 5.9.2016 Tiina Niklander Faculty of Science Department of Computer Science www.cs.helsinki.fi 5.9.2018 1 Learning goal objectives Language structures, data structures, modules,

More information

File Handling in C. EECS 2031 Fall October 27, 2014

File Handling in C. EECS 2031 Fall October 27, 2014 File Handling in C EECS 2031 Fall 2014 October 27, 2014 1 Reading from and writing to files in C l stdio.h contains several functions that allow us to read from and write to files l Their names typically

More information

Types, Operators and Expressions

Types, Operators and Expressions Types, Operators and Expressions EECS 2031 18 September 2017 1 Variable Names (2.1) l Combinations of letters, numbers, and underscore character ( _ ) that do not start with a number; are not a keyword.

More information

Main Program. C Programming Notes. #include <stdio.h> main() { printf( Hello ); } Comments: /* comment */ //comment. Dr. Karne Towson University

Main Program. C Programming Notes. #include <stdio.h> main() { printf( Hello ); } Comments: /* comment */ //comment. Dr. Karne Towson University C Programming Notes Dr. Karne Towson University Reference for C http://www.cplusplus.com/reference/ Main Program #include main() printf( Hello ); Comments: /* comment */ //comment 1 Data Types

More information

MODULE V: POINTERS & PREPROCESSORS

MODULE V: POINTERS & PREPROCESSORS MODULE V: POINTERS & PREPROCESSORS INTRODUCTION As you know, every variable is a memory-location and every memory-location has its address defined which can be accessed using ampersand(&) operator, which

More information

CS 326 Operating Systems C Programming. Greg Benson Department of Computer Science University of San Francisco

CS 326 Operating Systems C Programming. Greg Benson Department of Computer Science University of San Francisco CS 326 Operating Systems C Programming Greg Benson Department of Computer Science University of San Francisco Why C? Fast (good optimizing compilers) Not too high-level (Java, Python, Lisp) Not too low-level

More information

Quick review pointer basics (KR ch )

Quick review pointer basics (KR ch ) 1 Plan for today Quick review pointer basics (KR ch5.1 5.5) Related questions in midterm Continue on pointers (KR 5.6 -- ) Array of pointers Command line arguments Dynamic memory allocation (malloc) 1

More information

Lecture 8 Dynamic Memory Allocation

Lecture 8 Dynamic Memory Allocation Lecture 8 Dynamic Memory Allocation CS240 1 Memory Computer programs manipulate an abstraction of the computer s memory subsystem Memory: on the hardware side 3 @ http://computer.howstuffworks.com/computer-memory.htm/printable

More information

Topic 6: A Quick Intro To C. Reading. "goto Considered Harmful" History

Topic 6: A Quick Intro To C. Reading. goto Considered Harmful History Topic 6: A Quick Intro To C Reading Assumption: All of you know basic Java. Much of C syntax is the same. Also: Some of you have used C or C++. Goal for this topic: you can write & run a simple C program

More information

PES INSTITUTE OF TECHNOLOGY (BSC) I MCA, First IA Test, November 2015 Programming Using C (13MCA11) Solution Set Faculty: Jeny Jijo

PES INSTITUTE OF TECHNOLOGY (BSC) I MCA, First IA Test, November 2015 Programming Using C (13MCA11) Solution Set Faculty: Jeny Jijo PES INSTITUTE OF TECHNOLOGY (BSC) I MCA, First IA Test, November 2015 Programming Using C (13MCA11) Solution Set Faculty: Jeny Jijo 1. (a)what is an algorithm? Draw a flowchart to print N terms of Fibonacci

More information

Pointers (part 1) What are pointers? EECS We have seen pointers before. scanf( %f, &inches );! 25 September 2017

Pointers (part 1) What are pointers? EECS We have seen pointers before. scanf( %f, &inches );! 25 September 2017 Pointers (part 1) EECS 2031 25 September 2017 1 What are pointers? We have seen pointers before. scanf( %f, &inches );! 2 1 Example char c; c = getchar(); printf( %c, c); char c; char *p; c = getchar();

More information

Topic 6: A Quick Intro To C

Topic 6: A Quick Intro To C Topic 6: A Quick Intro To C Assumption: All of you know Java. Much of C syntax is the same. Also: Many of you have used C or C++. Goal for this topic: you can write & run a simple C program basic functions

More information

CS24 Week 2 Lecture 1

CS24 Week 2 Lecture 1 CS24 Week 2 Lecture 1 Kyle Dewey Overview C Review Void pointers Allocation structs void* (Void Pointers) void* Like any other pointer, it refers to some memory address However, it has no associated type,

More information

Arrays and Pointers. CSE 2031 Fall November 11, 2013

Arrays and Pointers. CSE 2031 Fall November 11, 2013 Arrays and Pointers CSE 2031 Fall 2013 November 11, 2013 1 Arrays l Grouping of data of the same type. l Loops commonly used for manipulation. l Programmers set array sizes explicitly. 2 Arrays: Example

More information

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language 1 History C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC

More information

Fundamentals of Programming

Fundamentals of Programming Fundamentals of Programming Lecture 4 Input & Output Lecturer : Ebrahim Jahandar Borrowed from lecturer notes by Omid Jafarinezhad Outline printf scanf putchar getchar getch getche Input and Output in

More information

UNIT- 3 Introduction to C++

UNIT- 3 Introduction to C++ UNIT- 3 Introduction to C++ C++ Character Sets: Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] =!= . $, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage

More information

Lecture 02 C FUNDAMENTALS

Lecture 02 C FUNDAMENTALS Lecture 02 C FUNDAMENTALS 1 Keywords C Fundamentals auto double int struct break else long switch case enum register typedef char extern return union const float short unsigned continue for signed void

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

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto Ricardo Rocha Department of Computer Science Faculty of Sciences University of Porto Adapted from the slides Revisões sobre Programação em C, Sérgio Crisóstomo Compilation #include int main()

More information

Fundamental of Programming (C)

Fundamental of Programming (C) Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi CE 43 - Fall 97 Lecture 4 Input and Output Department of Computer Engineering Outline printf

More information

Declaration. Fundamental Data Types. Modifying the Basic Types. Basic Data Types. All variables must be declared before being used.

Declaration. Fundamental Data Types. Modifying the Basic Types. Basic Data Types. All variables must be declared before being used. Declaration Fundamental Data Types All variables must be declared before being used. Tells compiler to set aside an appropriate amount of space in memory to hold a value. Enables the compiler to perform

More information

Programming in C. UVic SEng 265. Daniel M. German Department of Computer Science University of Victoria. October 23, 2002 Version: 1.

Programming in C. UVic SEng 265. Daniel M. German Department of Computer Science University of Victoria. October 23, 2002 Version: 1. Programming in C UVic SEng 265 Daniel M. German Department of Computer Science University of Victoria October 23, 2002 Version: 1.00 11 1 Programming in C (1.00) dmgerman@uvic.ca Parameter passing C implements

More information

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

Basic C Programming. Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island Basic C Programming Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island Announcements Exam 1 (20%): Feb. 27 (Tuesday) Tentative Proposal Deadline:

More information

Course Outline Introduction to C-Programming

Course Outline Introduction to C-Programming ECE3411 Fall 2015 Lecture 1a. Course Outline Introduction to C-Programming Marten van Dijk, Syed Kamran Haider Department of Electrical & Computer Engineering University of Connecticut Email: {vandijk,

More information

High Performance Computing in C and C++

High Performance Computing in C and C++ High Performance Computing in C and C++ Rita Borgo Computer Science Department, Swansea University Summary Introduction to C Writing a simple C program Compiling a simple C program Running a simple C program

More information

Mid-term Exam. Fall Semester 2017 KAIST EE209 Programming Structures for Electrical Engineering. Name: Student ID:

Mid-term Exam. Fall Semester 2017 KAIST EE209 Programming Structures for Electrical Engineering. Name: Student ID: Fall Semester 2017 KAIST EE209 Programming Structures for Electrical Engineering Mid-term Exam Name: This exam is closed book and notes. Read the questions carefully and focus your answers on what has

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

ANSI C Programming Simple Programs

ANSI C Programming Simple Programs ANSI C Programming Simple Programs /* This program computes the distance between two points */ #include #include #include main() { /* Declare and initialize variables */ double

More information

Lab Exam 1 D [1 mark] Give an example of a sample input which would make the function

Lab Exam 1 D [1 mark] Give an example of a sample input which would make the function CMPT 127 Spring 2019 Grade: / 20 First name: Last name: Student Number: Lab Exam 1 D400 1. [1 mark] Give an example of a sample input which would make the function scanf( "%f", &f ) return -1? Answer:

More information

P.G.TRB - COMPUTER SCIENCE. c) data processing language d) none of the above

P.G.TRB - COMPUTER SCIENCE. c) data processing language d) none of the above P.G.TRB - COMPUTER SCIENCE Total Marks : 50 Time : 30 Minutes 1. C was primarily developed as a a)systems programming language b) general purpose language c) data processing language d) none of the above

More information

These are reserved words of the C language. For example int, float, if, else, for, while etc.

These are reserved words of the C language. For example int, float, if, else, for, while etc. Tokens in C Keywords These are reserved words of the C language. For example int, float, if, else, for, while etc. Identifiers An Identifier is a sequence of letters and digits, but must start with a letter.

More information

Chapter 2 (Dynamic variable (i.e. pointer), Static variable)

Chapter 2 (Dynamic variable (i.e. pointer), Static variable) Chapter 2 (Dynamic variable (i.e. pointer), Static variable) August_04 A2. Identify and explain the error in the program below. [4] #include int *pptr; void fun1() { int num; num=25; pptr= &num;

More information

Programming, numerics and optimization

Programming, numerics and optimization Programming, numerics and optimization Lecture A-2: Programming basics II Łukasz Jankowski ljank@ippt.pan.pl Institute of Fundamental Technological Research Room 4.32, Phone +22.8261281 ext. 428 March

More information

The University of Nottingham

The University of Nottingham The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 2 MODULE, AUTUMN SEMESTER 2008 2009 C/C++ for Java Programmers Time allowed TWO hours Candidates may complete the front cover of their answer

More information

Princeton University COS 333: Advanced Programming Techniques A Subset of C90

Princeton University COS 333: Advanced Programming Techniques A Subset of C90 Princeton University COS 333: Advanced Programming Techniques A Subset of C90 Program Structure /* Print "hello, world" to stdout. Return 0. */ { printf("hello, world\n"); -----------------------------------------------------------------------------------

More information

Types, Operators and Expressions

Types, Operators and Expressions Types, Operators and Expressions CSE 2031 Fall 2011 9/11/2011 5:24 PM 1 Variable Names (2.1) Combinations of letters, numbers, and underscore character ( _ ) that do not start with a number; are not a

More information

High Performance Programming Programming in C part 1

High Performance Programming Programming in C part 1 High Performance Programming Programming in C part 1 Anastasia Kruchinina Uppsala University, Sweden April 18, 2017 HPP 1 / 53 C is designed on a way to provide a full control of the computer. C is the

More information

Lectures 5-6: Introduction to C

Lectures 5-6: Introduction to C Lectures 5-6: Introduction to C Motivation: C is both a high and a low-level language Very useful for systems programming Faster than Java This intro assumes knowledge of Java Focus is on differences Most

More information

Arrays and Pointers. Arrays. Arrays: Example. Arrays: Definition and Access. Arrays Stored in Memory. Initialization. EECS 2031 Fall 2014.

Arrays and Pointers. Arrays. Arrays: Example. Arrays: Definition and Access. Arrays Stored in Memory. Initialization. EECS 2031 Fall 2014. Arrays Arrays and Pointers l Grouping of data of the same type. l Loops commonly used for manipulation. l Programmers set array sizes explicitly. EECS 2031 Fall 2014 November 11, 2013 1 2 Arrays: Example

More information

ITC213: STRUCTURED PROGRAMMING. Bhaskar Shrestha National College of Computer Studies Tribhuvan University

ITC213: STRUCTURED PROGRAMMING. Bhaskar Shrestha National College of Computer Studies Tribhuvan University ITC213: STRUCTURED PROGRAMMING Bhaskar Shrestha National College of Computer Studies Tribhuvan University Lecture 07: Data Input and Output Readings: Chapter 4 Input /Output Operations A program needs

More information

Arithmetic Operators. Portability: Printing Numbers

Arithmetic Operators. Portability: Printing Numbers Arithmetic Operators Normal binary arithmetic operators: + - * / Modulus or remainder operator: % x%y is the remainder when x is divided by y well defined only when x > 0 and y > 0 Unary operators: - +

More information

C Syntax Arrays and Loops Math Strings Structures Pointers File I/O. Final Review CS Prof. Jonathan Ventura. Prof. Jonathan Ventura Final Review

C Syntax Arrays and Loops Math Strings Structures Pointers File I/O. Final Review CS Prof. Jonathan Ventura. Prof. Jonathan Ventura Final Review CS 2060 Variables Variables are statically typed. Variables must be defined before they are used. You only specify the type name when you define the variable. int a, b, c; float d, e, f; char letter; //

More information

Advanced Pointer Topics

Advanced Pointer Topics Advanced Pointer Topics Pointers to Pointers A pointer variable is a variable that takes some memory address as its value. Therefore, you can have another pointer pointing to it. int x; int * px; int **

More information

Dynamic Memory Management. Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

Dynamic Memory Management. Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island Dynamic Memory Management Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island 1 Dynamic Memory Allocation Dynamic memory allocation is used to

More information

Mid-term Exam. Fall Semester 2017 KAIST EE209 Programming Structures for Electrical Engineering. Name: Student ID:

Mid-term Exam. Fall Semester 2017 KAIST EE209 Programming Structures for Electrical Engineering. Name: Student ID: Fall Semester 2017 KAIST EE209 Programming Structures for Electrical Engineering Mid-term Exam Name: This exam is closed book and notes. Read the questions carefully and focus your answers on what has

More information

Continued from previous lecture

Continued from previous lecture The Design of C: A Rational Reconstruction: Part 2 Jennifer Rexford Continued from previous lecture 2 Agenda Data Types Statements What kinds of operators should C have? Should handle typical operations

More information