COP 3223 Final Review
|
|
- Amberly Phelps
- 5 years ago
- Views:
Transcription
1 COP 3223 Final Review Jennifer Brown December 2, Introduction 1.1 Variables I. How can we store data in a program? Initializing variables with data types A. Which of these are valid names for variables? i. 9length Not valid ii. hello Not valid iii. IamASuperCoolName Valid iv. int Not valid v. a new int Valid vi. str1 Valid II. Which way does assignment go? Right to left A. Which of these are valid if I have an int n; in main? i. 3 = n; Not valid ii. n = 5; Valid 1.2 Arithmetic I. What order of operations does the C compiler follow? A. Is it the same or different than PEMDAS? The compiler follows PEM- DAS along with other precedence rules B. If we have an int n; in main, what goes into n? i. n = / 2 * 7; 17 ii. n = (3 + 4) / 2 * 7; 21 iii. n = 4 * (1-8); -28 C. Is this valid? Neither of these are valid, there need to be a * operator if you want to multiply i. n = 4(1 + 2); ii. n = (3-2)(4 + 5); 1
2 1.3 Precedence I. Which operation executes first? A. i++; Post executes first B. ++i; II. What does the?: tertiary operator do? Simplified if statement A. What will these return? i. int a = 3, b = 1; (a > b)? a : b; Will return a ii. int a = 3, b = 5; (a > b)? a : b; Will return b B. Are there any other tertiary operators? No III. Which as higher precedence? A. Does the + execute before the =? Yes i. int b = 3 + 4; B. Additionally the + and = operators are... i. Unary? ii. Binary? Binary IV. Lets get fancy! What does the % operator do? A. How can we use mod to determine an even or odd number? Using % 2 B. How can we use mod to restrict range? Mod will restrict the numbers to 0 through n-1 C. What does mod do when we have rand()? Restricts what random numbers we get 1.4 Data Types I. What is a data type? Determines what type of data A. What type of data do these create? i. int Integer ii. float Floating decimal iii. double Double float iv. int * Integer pointer v. void No data, used in functions 2
3 1.5 Conversion Specifiers I. What is a conversion specifier (format code etc)? Changes the way data is read or written A. What do the following codes display in a printf? 2 Functions 2.1 Main i. %d Decimal integer ii. %f Floating point iii. %c Character iv. %lf Double/long float v. %p Pointer address I. Let s break down the main function! A. int main(void) { return 0; } i. What data type does main return? Integer ii. What parameters does main take in? None iii. What does main return? 0 iv. Can I have no main function? No v. Can I have 2 main functions? No II. What is this clever little void we keep seeing? return type or no parameters Used when there is no III. What is the difference between pass by value and pass by reference? Pass by value passes the values variables contain, pass by reference passes the addresses fo the variables 2.2 Writing Functions and Function Prototypes I. How do we build our own functions? We define them in our code A. What do we need? i. Data type What will be returned ii. Name The function name iii. Parameters What values are taken in by the function iv. Return Unless void, must return II. Let s look at the following function prototypes A. void swap(int *a, int *b); B. int max int(int x, int y); 3
4 i. What parameters do they take in? Swamp function takes in two pointers to integers, max takes in two integers ii. What do they return? Void returns nothing, int returns an integer III. Let s finish up the max function! A. The function max will find the biggest number and return that value Link 3 Conditionals 3.1 Decisions I. What keyword do we use when making decisions? If A. When do we execute a decisions? Will these execute? Only executes if statement is true i. int a = 3, b = 1; if (a > b) Will execute ii. int a = 3, b = 1; if (a < b) Will not execute iii. if (1) Will execute iv. if (0) Will not execute v. if (a = 1) Will execute always, since assignment was successful a. Oh no! Did we do this right? Will want to use the == instead B. What comparisons can we make? i. >=, <= ii. ==,!= iii. <, > 3.2 Boolean Logic I. We saw some tricky numbers in our decisions! Let s review Boolean logic, what does the compiler see as true and as false when we get sneaky numbers? The compiler will see anything that is a 0 or equivalent as false and all other numbers as true II. What if we want to compare more than one thing at a time? Must use logical operators A. What do these operators do? i. && Logical AND ii. Logical OR 4
5 B. If we have a and the first comparison is true, do we check the second one? Does it matter? We do not i. Likewise, if we have a &&, and the first comparison is false, do we compare the second? Does it matter? We do not ii. What is this called? Short circuiting 3.3 If/Else if/else I. What keyword do we use if we want to execute when the condition is false? A. Let s write a nested if/if else/else that determines the age of the user, and then tells them if they can vote, drink alcohol, both, or neither. We fancy! Link 4 Loops When we want to make a decision over and over again, we use loops. What are different types of loops we have? While, do while, for 4.1 While Loop I. How does the while loop work? while (condition) A. What happens in these loops? 4.2 For Loop i. int i = 3; while (i!= -1) printf( %d, i ; Loops until -1 is reached ii. while (i!= 1); { printf( Hurray!); i = 1; } a. Oh no! This looks like it would work, but it doesn t! What happened? The ; after the loop causes the loop to infinitely run I. How does the for loop work? for(pre; condition; post) A. What happens in these loops? i. for (i = 0; i < 5; i++) printf( %d, i); Prints 0-4 ii. for(;;) 5
6 4.3 Do While Loop a. This looks a little funky, is this still valid? Yes, but will loop infinitely b. What is the minimum thing that for loops require?two semicolons I. How does the do while loop work? Executes the do first and then checks the condition A. What happens in these loops? i. do printf( Yasssss ); while (0); a. Oh lookie, we have some tricksy numbers again in our loops. What do we do? Will not execute, only prints the print statement b. Does this execute at least once? Yes c. How is it different than a while loop? Always executes once 5 Break/Continue 5.1 Break I. What do we do when we want to leave a loop early? Break A. Let s write loop that adds to a total as long as the numbers are even Link 5.2 Continue I. What do we do when we want to skip a certain case and continue looping? continue statement A. Let s write a loop that keeps looping as long as the user doesn t put in negative numbers, but skips odds. Link i. Depending on your logic, continue can very easily cause nasty infinite loops. Let s fix the following code: a. int i = 0; while (i < 7) if (i == 2) continue; i++ } Must add i++ after the if statement 6
7 6 Switch 6.1 Decisions I. Now that we are master of if/else if/else, let s explore another way to do this with switch statements A. How do we write a switch? Switch keyword, and the cases i. Let s write a switch that takes in a letter grade and tells the user what range that grade will be in. Link B. in the following code, what will happen? i. char a = a ; switch(a) { case a : printf( a ); case b : printf( b ); } a. Something horrible happened! What happened and how do we fix it? This will print both a and b, needs a break statement b. What is so important about break in switch statements? Stops the cases from falling through C. Is the default case in a switch statement important? To what is it similar to in if/else if/else? The default case is the catch all at the end, used for unexpected values, and is simliar to else 7 Pointers 7.1 Data Type I. What type of data does a pointer contain? An address A. How do you initialize a pointer? Data type and then * B. What does the following code do? i. int a; int *p; *p = 5; a. DANGER! Something VERY BAD has happened! What is it and why is it so VERY BAD? We are attempting to dereference an uninitialized pointer, and placing the 5 into a random place in memory 7
8 b. What is dereferencing, and how can we do it without self destructing our code? Dereferencing means going to the address at which a pointer points to and then changing the value, this code can be fixed by changing int *p to int *p = &a ii. int a; int *p = NULL; *p = 5; a. Oh no! We also seg faulted here, what happened? Simliarly here, we tried to place a 5 into nowhere, and the compiler cannot find a place to put it b. Can we dereference a null pointer? We will seg fault 7.2 Functions with Pointers I. We saw earlier that swap prototype, but we didn t write it! Now that we have reviewed pointers, we are ready to tackle it. A. Recall: void swap(int *a, int *b); i. Why do we need the pointers, and how can we finish up this function? Link B. Let s also write a findmax function using pointers i. Prototype: int findmax(int *x, int *y); ii. This can also be achieved via pass by value, but we want to be fancy and use pointers instead. iii. Why do we need to change the return value from void to int? We want to return the max of the two 7.3 Pointer pointers I. What type of data does a pointer to a pointer contain? An address to an address that point to a data type A. How do you initialize a pointer to a pointer? ** B. How do I use the q pointer to manipulate a in the following code? i. int a; int *p = &a; int **q = &p; **q = 5; C. What s wrong with the following code? i. int a; int *p; int **q; **q = 5; 8
9 a. This code is spooky scary, why is that? We have two uninitialized pointers, and neither points to a non-random address, see question above for fix 8 File I/O I. What is File I/O? reading and writing from a file outside the program A. What code would we use to open a.txt file? We need both FILE *pointer name and fopen 8.1 File I/O Functions I. What functions can we use once we have opened a file? A. What do the following functions do? i. fopen(); a. Syntax? fopen(name, mode) ii. fscanf(); a. Syntax? fscanf(file pointer, converstion specifier, destination iii. fgets(); a. Syntax? fgets(destination, length, file pointer iv. fprintf(); a. Syntax? fprintf(file pointer, converstion specifier, source v. fputs(); a. Syntax? fputs(source, file pointer) vi. fclose(); a. Syntax? fclose(file pointer) 8.2 Reading a file I. What code do we write to read from a.txt file? fopen, fscanf/fgets, fclose A. What functions do we need? i. fopen? Yes ii. fscanf? Possible iii. fgets? Possible iv. fprintf? This function writes to a file v. fputs? This function writes to a file vi. fclose? Yes B. Let s write a function that reads names from a file and then prints them. Link 9
10 9 ASCII 9.1 Do characters have values? I. If I have the letter/char a, what value would it have? 97 A. Look at the following code: i. char a = a ; printf( %d, a); a. What do you think it will print? This will print the ASCII value of a, 97 B. What about this? 9.2 ASCII Table i. int a = 97; printf( %c, a); This will print the what ASCII letter the integer has a. Crazy magic! This code is valid, why is that? This is valid because all characters have set values I. Let s write a function that prints the ASCII values of First it will print the integer value and then the character. Link A. What value is 1? 49 B. What value is A? 65 C. What value is a? Arrays and Strings 10.1 Arrays I. What is an array? An array is a complex data type that contains cells of a primitive data type consecutively A. Is the data in an array consecutive? Yes i. How do i initialize an array? datatype arrayname[numberofcells]; ii. Where does the index of an array always start? 0 II. What will the following code do? A. int arr[5] = {1, 2, 3}, i; Initializes an array with 5 cells in it for(i = 0; i < 5; i++) printf( %d, arr[i]); i. If I have the code arr[5]; what values are in the cells of the array? This will print
11 10.2 Passing arrays I. If I want to pass an array to a function, what do I send in the function call? The array name A. What parameter will hold what we are sending? We will need a pointer of the array s datatype B. If I have an array called array and I send it to a max function (returns the max value in the array), what am I technically sending? The address of the 0 index of the array, or the beginning i. IE: int array[5] = {4, 7, 6, 9, 1}, n = 5; max(array, n); a. What does the max prototype look like? int max(int *array, n) II. When passing arrays, why do we need a pointer? Arrays are a type of pointer A. Let s write that max function! i. Takes in an array and a length ii. Returns the max value in that array Link B. Let s write a min function 10.3 Strings i. Takes in an array and a length ii. Returns the max value in that array Link I. How are strings different from arrays? Strings are an array of characters that also contain a null terminator /0 II. How are are they the same? They are still both arrays A. What data type are the cells in a string? char B. What extra value do we have at the end of a string? The null terminator i. What happens if our array is too small to hold the null terminator? The compiler will not know when the string ends C. When we pass a string to a function, is it similar to an array? Yes, it will utilize a pointer i. What is different? Must be datatype char D. What will the following code print? 11
12 i. char str[6] = hello ; int i; for (i = 0; i < 6; i++) printf( %c str[i]); This will print each character of the string E. Let s write a function that finds the smallest alphabetical letter. IE: a is smaller than b Link F. Let s write a function that finds the biggest alphabetical letter. IE: z is bigger than y Link 10.4 String Functions I. What library do we need to use string functions? string.h II. What are some of the string functions that we can use? A. What do the following functions do? i. strlen(); Finds the length of the string a. Syntax? strlen(string) ii. strcmp(); Compares two strings, returns 0 if the same a. Syntax? strcomp(str1, str2) iii. strcpy(); Copies one string to another a. Syntax? strcpy(destination, source) iv. strcat(); Adds a string to the end of another strcat(destination, source) a. Syntax? v. strstr(); Finds if a string is inside another string, returns the string found a. Syntax? strstr(haystack, needle) B. When using string functions, what do we have to be careful of? Can we segmentation fault? We have to be careful we are not placing a string bigger than its destination i. What could go wrong with the following code? a. char str[6] = { hello }; strcat(str, helloooooo ); str is not big enough to add this to ii. What went wrong and why? Went out of bounds of memory 11 2D Arrays I. What does a 2D Array look like? A coordinate system A. How can we loop through a 2D array and set values to 0? We need to loop through the rows and the columns 12
13 i. Can we do this with one loop or do we need two? Need two ii. Are 2D arrays similar to a coordinate system? Yes B. When initializing a 2D array, it looks like: int arr[ ][ ]; i. Which spot sets the rows? The first ii. Which spot sets the columns? The second C. When using loops to manipulate 2D arrays: i. If we have i for loop 1 and j for loop 2 a. Does i correspond to: rows or columns? rows b. Does j correspond to: rows or columns? columns 12 Dynamic Memory Allocation (DMA) I. Why do we want to use dynamic memory allocation instead of static? In case we do not know how big an array needs to be yet A. Do we always know how big we want an array to be? Not always! B. Do we always know how big we want a string to be? Not always! II. In order to create an array dynamically, what do we need first? We need a pointer and then a malloc call A. What functions do we use? malloc and calloc i. What does malloc do? Allocates a new space in memory ii. What does calloc do? redallocates a new space in memory and sets the values to 0 or NULL III. What is wrong with the following code? A. int *p, i, n = 5; for (i = 0; i 5; i++) p = malloc(sizeof(int) * n); 13 Structures i. DANGER! Something very bad is happening here, what is it, and why? Allocates a new space in memory each time with only one pointer. Once the pointer moves to the new one, the address of the old is lost! I. Why are structures used? Why are they super mega awesome? Structures allow us to create our own datatypes, this is really cool and awesome! They are used if we want information to be packaged together 13
14 A. Structures are known as abstract data types, why do you think they are called this? Because they are defined in code, and can be anything they dream to be II. Is memory allocated in the following code? Not yet, only defined A. struct StudentInfo { char *name int ID; } ; i. There is an error here, what is it? Needs a semi-colon at the end III. How do I make a new struct? The struct must be defined, and then we call the struct in main using the entire name, unless typdef was used A. What is wrong with the following code? i. int main(void) { StudentInfo newstudent; return 0; } This needs to have the word struct in front of it to be valid a. How can we change the struct so that this code is A-OK? We can typdef our struct: typdef struct StudentInfo { char *name int ID; } StudentInfo; B. How do we change the values in a struct when it s been initialized? We have to use variablename.datatype i. Let s change the ID to , how do we write that in code? newstudent.id = ; ii. Let s make the name Aleks, how do we write that in code? newstudent.name = malloc((sizeof(char) * n) + 1); strcpy(newstudent.name, Aleks ); IV. Can we create a pointer to a struct? A. How would that look? How do we code that? Struct name *newvariable B. How would we change the data with a pointer? Since this is now a pointer to a struct, we must dereference first using * and then use the. i. Do we still need to dereference? Yes ii. Is there a sneaky shortcut we can use other than *.? We can use - instead C. What benefit is there in creating a pointer to a struct? We can now store those pointers into an array, and have them collected together in a database 14
COP 3223 Final Review
COP 3223 Final Review Jennifer Brown December 2, 2018 1 Introduction 1.1 Variables I. How can we store data in a program? A. Which of these are valid names for variables? i. 9length ii. hello iii. IamASuperCoolName
More informationCOP 3223 Introduction to Programming with C - Study Union - Spring 2018
COP 3223 Introduction to Programming with C - Study Union - Spring 2018 Chris Marsh and Matthew Villegas Contents 1 Code Tracing 2 2 Pass by Value Functions 4 3 Statically Allocated Arrays 5 3.1 One Dimensional.................................
More informationC 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 informationLectures 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 informationC programming basics T3-1 -
C programming basics T3-1 - Outline 1. Introduction 2. Basic concepts 3. Functions 4. Data types 5. Control structures 6. Arrays and pointers 7. File management T3-2 - 3.1: Introduction T3-3 - Review of
More informationCOP 3223 Introduction to Programming with C - Study Union - Fall 2017
COP 3223 Introduction to Programming with C - Study Union - Fall 2017 Chris Marsh and Matthew Villegas Contents 1 Code Tracing 2 2 Pass by Value Functions 4 3 Statically Allocated Arrays 5 3.1 One Dimensional.................................
More informationCS 222: Pointers and Manual Memory Management
CS 222: Pointers and Manual Memory Management Chris Kauffman Week 4-1 Logistics Reading Ch 8 (pointers) Review 6-7 as well Exam 1 Back Today Get it in class or during office hours later HW 3 due tonight
More informationTo declare an array in C, a programmer specifies the type of the elements and the number of elements required by an array as follows
Unti 4: C Arrays Arrays a kind of data structure that can store a fixed-size sequential collection of elements of the same type An array is used to store a collection of data, but it is often more useful
More informationFor example, let s say we define an array of char of size six:
Arrays in C++ An array is a consecutive group of memory locations that all have the same name and the same type. To refer to a particular location, we specify the name and then the positive index into
More informationCOP 3223 Introduction to Programming with C - Study Union - Fall 2017
COP 3223 Introduction to Programming with C - Study Union - Fall 2017 Chris Marsh and Matthew Villegas Contents 1 Code Tracing 2 2 Pass by Value Functions 4 3 Statically Allocated Arrays 5 3.1 One Dimensional.................................
More informationB.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 informationhttps://www.eskimo.com/~scs/cclass/notes/sx8.html
1 de 6 20-10-2015 10:41 Chapter 8: Strings Strings in C are represented by arrays of characters. The end of the string is marked with a special character, the null character, which is simply the character
More informationFloating-point lab deadline moved until Wednesday Today: characters, strings, scanf Characters, strings, scanf questions clicker questions
Announcements Thursday Extras: CS Commons on Thursdays @ 4:00 pm but none next week No office hours next week Monday or Tuesday Reflections: when to use if/switch statements for/while statements Floating-point
More informationFall 2018 Discussion 2: September 3, 2018
CS 61C C Basics Fall 2018 Discussion 2: September 3, 2018 1 C C is syntactically similar to Java, but there are a few key differences: 1. C is function-oriented, not object-oriented; there are no objects.
More informationAryan College. Fundamental of C Programming. Unit I: Q1. What will be the value of the following expression? (2017) A + 9
Fundamental of C Programming Unit I: Q1. What will be the value of the following expression? (2017) A + 9 Q2. Write down the C statement to calculate percentage where three subjects English, hindi, maths
More informationContents. A Review of C language. Visual C Visual C++ 6.0
A Review of C language C++ Object Oriented Programming Pei-yih Ting NTOU CS Modified from www.cse.cuhk.edu.hk/~csc2520/tuto/csc2520_tuto01.ppt 1 2 3 4 5 6 7 8 9 10 Double click 11 12 Compile a single source
More informationtoday cs3157-fall2002-sklar-lect05 1
today homework #1 due on monday sep 23, 6am some miscellaneous topics: logical operators random numbers character handling functions FILE I/O strings arrays pointers cs3157-fall2002-sklar-lect05 1 logical
More informationMain 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 informationLecture 4: Outline. Arrays. I. Pointers II. III. Pointer arithmetic IV. Strings
Lecture 4: Outline I. Pointers A. Accessing data objects using pointers B. Type casting with pointers C. Difference with Java references D. Pointer pitfalls E. Use case II. Arrays A. Representation in
More informationC for C++ Programmers
C for C++ Programmers CS230/330 - Operating Systems (Winter 2001). The good news is that C syntax is almost identical to that of C++. However, there are many things you're used to that aren't available
More informationCSCI 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 informationBASIC ELEMENTS OF A COMPUTER PROGRAM
BASIC ELEMENTS OF A COMPUTER PROGRAM CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING LOGO Contents 1 Identifier 2 3 Rules for naming and declaring data variables Basic data types 4 Arithmetic operators
More informationPointer Basics. Lecture 13 COP 3014 Spring March 28, 2018
Pointer Basics Lecture 13 COP 3014 Spring 2018 March 28, 2018 What is a Pointer? A pointer is a variable that stores a memory address. Pointers are used to store the addresses of other variables or memory
More informationSYSC 2006 C Winter 2012
SYSC 2006 C Winter 2012 Pointers and Arrays Copyright D. Bailey, Systems and Computer Engineering, Carleton University updated Sept. 21, 2011, Oct.18, 2011,Oct. 28, 2011, Feb. 25, 2011 Memory Organization
More informationC mini reference. 5 Binary numbers 12
C mini reference Contents 1 Input/Output: stdio.h 2 1.1 int printf ( const char * format,... );......................... 2 1.2 int scanf ( const char * format,... );.......................... 2 1.3 char
More informationLectures 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 informationCS 61c: Great Ideas in Computer Architecture
Arrays, Strings, and Some More Pointers June 24, 2014 Review of Last Lecture C Basics Variables, functioss, control flow, types, structs Only 0 and NULL evaluate to false Pointers hold addresses Address
More informationCS 61C: Great Ideas in Computer Architecture. C Arrays, Strings, More Pointers
CS 61C: Great Ideas in Computer Architecture C Arrays, Strings, More Pointers Instructor: Justin Hsia 6/20/2012 Summer 2012 Lecture #3 1 Review of Last Lecture C Basics Variables, Functions, Flow Control,
More informationCourse organization. Course introduction ( Week 1)
Course organization Course introduction ( Week 1) Code editor: Emacs Part I: Introduction to C programming language (Week 2-9) Chapter 1: Overall Introduction (Week 1-3) Chapter 2: Types, operators and
More informationH192 Midterm 1 Review. Tom Zajdel
H192 Midterm 1 Review Tom Zajdel Declaring variables Need to specify a type when declaring a variable. Can declare multiple variables in one line. int x, y, z; float a, b, c; Can also initialize in same
More informationProcedural Programming & Fundamentals of Programming
Procedural Programming & Fundamentals of Programming Lecture 3 - Summer Semester 2018 & Joachim Zumbrägel What we know so far... Data type serves to organize data (in the memory), its possible values,
More informationOutput of sample program: Size of a short is 2 Size of a int is 4 Size of a double is 8
Pointers Variables vs. Pointers: A variable in a program is something with a name and a value that can vary. The way the compiler and linker handles this is that it assigns a specific block of memory within
More informationAnnouncements. assign0 due tonight. Labs start this week. No late submissions. Very helpful for assign1
Announcements assign due tonight No late submissions Labs start this week Very helpful for assign1 Goals for Today Pointer operators Allocating memory in the heap malloc and free Arrays and pointer arithmetic
More informationIntroduction to Computer Science Midterm 3 Fall, Points
Introduction to Computer Science Fall, 2001 100 Points Notes 1. Tear off this sheet and use it to keep your answers covered at all times. 2. Turn the exam over and write your name next to the staple. Do
More informationFile I/O. Arash Rafiey. November 7, 2017
November 7, 2017 Files File is a place on disk where a group of related data is stored. Files File is a place on disk where a group of related data is stored. C provides various functions to handle files
More informationArrays and Pointers in C. Alan L. Cox
Arrays and Pointers in C Alan L. Cox alc@rice.edu Objectives Be able to use arrays, pointers, and strings in C programs Be able to explain the representation of these data types at the machine level, including
More informationCS 31: Intro to Systems Arrays, Structs, Strings, and Pointers. Kevin Webb Swarthmore College March 1, 2016
CS 31: Intro to Systems Arrays, Structs, Strings, and Pointers Kevin Webb Swarthmore College March 1, 2016 Overview Accessing things via an offset Arrays, Structs, Unions How complex structures are stored
More informationIntroduction to Programming in C Department of Computer Science and Engineering. Lecture No. #29 Arrays in C
Introduction to Programming in C Department of Computer Science and Engineering Lecture No. #29 Arrays in C (Refer Slide Time: 00:08) This session will learn about arrays in C. Now, what is the word array
More informationLecture 05 I/O statements Printf, Scanf Simple statements, Compound statements
Programming, Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science and Engineering Indian Institute of Technology, Madras Lecture 05 I/O statements Printf, Scanf Simple
More informationC 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 informationC 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 informationHigh-performance computing and programming Intro to C on Unix/Linux. Uppsala universitet
High-performance computing and programming Intro to C on Unix/Linux IT Uppsala universitet What is C? An old imperative language that remains rooted close to the hardware C is relatively small and easy
More informationHighlights. - Making threads. - Waiting for threads. - Review (classes, pointers, inheritance)
Parallel processing Highlights - Making threads - Waiting for threads - Review (classes, pointers, inheritance) Review: CPUs Review: CPUs In the 2000s, computing too a major turn: multi-core processors
More informationMultidimension array, array of strings
1 Multidimension array, array of strings char messages[3][7] ={ Hello, Hi, There ; Array of strings 0 1 2 0 1 2 3 4 5 6 H e l l o \0 H i \0 T h e r e \0 Each row (e.g., message[0]) is a char array (string)
More informationCS201- Introduction to Programming Latest Solved Mcqs from Midterm Papers May 07,2011. MIDTERM EXAMINATION Spring 2010
CS201- Introduction to Programming Latest Solved Mcqs from Midterm Papers May 07,2011 Lectures 1-22 Moaaz Siddiq Asad Ali Latest Mcqs MIDTERM EXAMINATION Spring 2010 Question No: 1 ( Marks: 1 ) - Please
More informationLecture Programming in C++ PART 1. By Assistant Professor Dr. Ali Kattan
Lecture 08-1 Programming in C++ PART 1 By Assistant Professor Dr. Ali Kattan 1 The Conditional Operator The conditional operator is similar to the if..else statement but has a shorter format. This is useful
More informationFinal Intro to C Review
Final Exam Content: Final Intro to C Review - Pass by reference Functions - General Syntax - Structures - Recursion(maybe?) - Programming by nature is cumulative so any past material is up for grabs as
More informationFlow Control. CSC215 Lecture
Flow Control CSC215 Lecture Outline Blocks and compound statements Conditional statements if - statement if-else - statement switch - statement? : opertator Nested conditional statements Repetitive statements
More informationCENG 447/547 Embedded and Real-Time Systems. Review of C coding and Soft Eng Concepts
CENG 447/547 Embedded and Real-Time Systems Review of C coding and Soft Eng Concepts Recall (C-style coding syntax) ; - Indicate the end of an expression {} - Used to delineate when a sequence of elements
More informationCS201 Some Important Definitions
CS201 Some Important Definitions For Viva Preparation 1. What is a program? A program is a precise sequence of steps to solve a particular problem. 2. What is a class? We write a C++ program using data
More informationComp 11 Lectures. Mike Shah. June 26, Tufts University. Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57
Comp 11 Lectures Mike Shah Tufts University June 26, 2017 Mike Shah (Tufts University) Comp 11 Lectures June 26, 2017 1 / 57 Please do not distribute or host these slides without prior permission. Mike
More informationgcc 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 informationARRAYS(II Unit Part II)
ARRAYS(II Unit Part II) Array: An array is a collection of two or more adjacent cells of similar type. Each cell in an array is called as array element. Each array should be identified with a meaningful
More informationKurt 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 informationPointers, Dynamic Data, and Reference Types
Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation The new operator The delete operator Dynamic Memory Allocation for Arrays 1 C++ Data Types simple
More informationCS201- Introduction to Programming Current Quizzes
CS201- Introduction to Programming Current Quizzes Q.1 char name [] = Hello World ; In the above statement, a memory of characters will be allocated 13 11 12 (Ans) Q.2 A function is a block of statements
More informationSYSC 2006 C Winter String Processing in C. D.L. Bailey, Systems and Computer Engineering, Carleton University
SYSC 2006 C Winter 2012 String Processing in C D.L. Bailey, Systems and Computer Engineering, Carleton University References Hanly & Koffman, Chapter 9 Some examples adapted from code in The C Programming
More informationC: 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 informationEMBEDDED SYSTEMS PROGRAMMING Language Basics
EMBEDDED SYSTEMS PROGRAMMING 2015-16 Language Basics "The tower of Babel" by Pieter Bruegel the Elder Kunsthistorisches Museum, Vienna (PROGRAMMING) LANGUAGES ABOUT THE LANGUAGES C (1972) Designed to replace
More informationLanguage comparison. C has pointers. Java has references. C++ has pointers and references
Pointers CSE 2451 Language comparison C has pointers Java has references C++ has pointers and references Pointers Values of variables are stored in memory, at a particular location A location is identified
More informationIntroduction to Programming Using Java (98-388)
Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;
More informationFirst of all, it is a variable, just like other variables you studied
Pointers: Basics What is a pointer? First of all, it is a variable, just like other variables you studied So it has type, storage etc. Difference: it can only store the address (rather than the value)
More informationQUIZ. 1. Explain the meaning of the angle brackets in the declaration of v below:
QUIZ 1. Explain the meaning of the angle brackets in the declaration of v below: This is a template, used for generic programming! QUIZ 2. Why is the vector class called a container? 3. Explain how the
More informationThere are functions to handle strings, so we will see the notion of functions itself in little a detail later. (Refer Slide Time: 00:12)
Programming Data Structures, Algorithms Prof. Shankar Balachandran Department of Computer Science and Engineering Indian Institute of Technology, Madras Module - 13b Lecture - 19 Functions to handle strings;
More informationFinal exam. Final exam will be 12 problems, drop any 2. Cumulative up to and including week 14 (emphasis on weeks 9-14: classes & pointers)
Review Final exam Final exam will be 12 problems, drop any 2 Cumulative up to and including week 14 (emphasis on weeks 9-14: classes & pointers) 2 hours exam time, so 12 min per problem (midterm 2 had
More informationC introduction: part 1
What is C? C is a compiled language that gives the programmer maximum control and efficiency 1. 1 https://computer.howstuffworks.com/c1.htm 2 / 26 3 / 26 Outline Basic file structure Main function Compilation
More informationOther C materials before pointer Common library functions [Appendix of K&R] 2D array, string manipulations. <stdlib.
1 The previous lecture Other C materials before pointer Common library functions [Appendix of K&R] 2D array, string manipulations Pointer basics 1 Common library functions [Appendix of K+R]
More informationPointers in C/C++ 1 Memory Addresses 2
Pointers in C/C++ Contents 1 Memory Addresses 2 2 Pointers and Indirection 3 2.1 The & and * Operators.............................................. 4 2.2 A Comment on Types - Muy Importante!...................................
More informationType Conversion. and. Statements
and Statements Type conversion changing a value from one type to another Void Integral Floating Point Derived Boolean Character Integer Real Imaginary Complex no fractional part fractional part 2 tj Suppose
More informationOverview. Concepts this lecture String constants Null-terminated array representation String library <strlib.h> String initializers Arrays of strings
CPE 101 slides based on UW course Lecture 19: Strings Overview Concepts this lecture String constants ull-terminated array representation String library String initializers Arrays of strings
More informationmith College Computer Science CSC270 Spring 2016 Circuits and Systems Lecture Notes, Week 11 Dominique Thiébaut
mith College Computer Science CSC270 Spring 2016 Circuits and Systems Lecture Notes, Week 11 Dominique Thiébaut dthiebaut@smithedu Outline A Few Words about HW 8 Finish the Input Port Lab! Revisiting Homework
More informationStrings(2) CS 201 String. String Constants. Characters. Strings(1) Initializing and Declaring String. Debzani Deb
CS 201 String Debzani Deb Strings(2) Two interpretations of String Arrays whose elements are characters. Pointer pointing to characters. Strings are always terminated with a NULL characters( \0 ). C needs
More informationAN OVERVIEW OF C, PART 3. CSE 130: Introduction to Programming in C Stony Brook University
AN OVERVIEW OF C, PART 3 CSE 130: Introduction to Programming in C Stony Brook University FANCIER OUTPUT FORMATTING Recall that you can insert a text field width value into a printf() format specifier:
More informationIntroduction to Scientific Computing and Problem Solving
Introduction to Scientific Computing and Problem Solving Lecture #22 Pointers CS4 - Introduction to Scientific Computing and Problem Solving 2010-22.0 Announcements HW8 due tomorrow at 2:30pm What s left:
More informationESC101N: Fundamentals of Computing End-sem st semester
ESC101N: Fundamentals of Computing End-sem 2010-11 1st semester Instructor: Arnab Bhattacharya 8:00-11:00am, 15th November, 2010 Instructions 1. Please write your name, roll number and section below. 2.
More informationStandard C Library Functions
Demo lecture slides Although I will not usually give slides for demo lectures, the first two demo lectures involve practice with things which you should really know from G51PRG Since I covered much of
More informationCS 31 Review Sheet. Tau Beta Pi - Boelter Basics 2. 2 Working with Decimals 2. 4 Operators 3. 6 Constants 3.
CS 31 Review Sheet Tau Beta Pi - Boelter 6266 Contents 1 Basics 2 2 Working with Decimals 2 3 Handling Strings and Numbers with stdin/stdout 3 4 Operators 3 5 Common Mistakes/Misconceptions 3 6 Constants
More informationCS107 Spring 2019, Lecture 4 C Strings
CS107 Spring 2019, Lecture 4 C Strings Reading: K&R (1.9, 5.5, Appendix B3) or Essential C section 3 This document is copyright (C) Stanford Computer Science and Nick Troccoli, licensed under Creative
More informationFile IO and command line input CSE 2451
File IO and command line input CSE 2451 File functions Open/Close files fopen() open a stream for a file fclose() closes a stream One character at a time: fgetc() similar to getchar() fputc() similar to
More informationEuclid s algorithm, 133
Index A Algorithm computer instructions, 4 data and variables, 5 develop algorithm, 6 American Standard Code for Information Interchange (ASCII) codes, 141 definition, 142 features, 142 Arithmetic expressions
More informationAgenda. Components of a Computer. Computer Memory Type Name Addr Value. Pointer Type. Pointers. CS 61C: Great Ideas in Computer Architecture
CS 61C: Great Ideas in Computer Architecture Krste Asanović & Randy Katz http://inst.eecs.berkeley.edu/~cs61c And in Conclusion, 2 Processor Control Datapath Components of a Computer PC Registers Arithmetic
More informationCS1100 Introduction to Programming
CS1100 Introduction to Programming Sorting Strings and Pointers Madhu Mutyam Department of Computer Science and Engineering Indian Institute of Technology Madras Lexicographic (Dictionary) Ordering Badri
More informationCSC 2400: Computer Systems. Arrays and Strings in C
CSC 2400: Computer Systems Arrays and Strings in C Lecture Overview Arrays! List of elements of the same type Strings! Array of characters ending in \0! Functions for manipulating strings 1 Arrays in C
More informationCS107 Handout 08 Spring 2007 April 9, 2007 The Ins and Outs of C Arrays
CS107 Handout 08 Spring 2007 April 9, 2007 The Ins and Outs of C Arrays C Arrays This handout was written by Nick Parlante and Julie Zelenski. As you recall, a C array is formed by laying out all the elements
More informationECE2049 E17 Lecture 2: Data Representations & C Programming Basics
ECE2049 E17 Lecture 2: Data Representations & C Programming Basics Administrivia Lab 0 after class today! o Get your MSP430 board! Install instructions for CCS are on course website under Resources o You
More informationWrite a C program using arrays and structure
03 Arrays and Structutes 3.1 Arrays Declaration and initialization of one dimensional, two dimensional and character arrays, accessing array elements. (10M) 3.2 Declaration and initialization of string
More informationPointers (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 informationCS 61C: Great Ideas in Computer Architecture. Lecture 3: Pointers. Krste Asanović & Randy Katz
CS 61C: Great Ideas in Computer Architecture Lecture 3: Pointers Krste Asanović & Randy Katz http://inst.eecs.berkeley.edu/~cs61c Agenda Pointers in C Arrays in C This is not on the test Pointer arithmetic
More informationCompiling and Running a C Program in Unix
CPSC 211 Data Structures & Implementations (c) Texas A&M University [ 95 ] Compiling and Running a C Program in Unix Simple scenario in which your program is in a single file: Suppose you want to name
More informationObject Oriented Pragramming (22316)
Chapter 1 Principles of Object Oriented Programming (14 Marks) Q1. Give Characteristics of object oriented programming? Or Give features of object oriented programming? Ans: 1. Emphasis (focus) is on data
More informationAgenda. Peer Instruction Question 1. Peer Instruction Answer 1. Peer Instruction Question 2 6/22/2011
CS 61C: Great Ideas in Computer Architecture (Machine Structures) Introduction to C (Part II) Instructors: Randy H. Katz David A. Patterson http://inst.eecs.berkeley.edu/~cs61c/sp11 Spring 2011 -- Lecture
More informationImportant Questions for Viva CPU
Important Questions for Viva CPU 1. List various components of a computer system. i. Input Unit ii. Output Unit iii. Central processing unit (Control Unit + Arithmetic and Logical Unit) iv. Storage Unit
More informationHigh 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 informationSAE1A Programming in C. Unit : I - V
SAE1A Programming in C Unit : I - V Unit I - Overview Character set Identifier Keywords Data Types Variables Constants Operators SAE1A - Programming in C 2 Character set of C Character set is a set of
More information211: Computer Architecture Summer 2016
211: Computer Architecture Summer 2016 Liu Liu Topic: C Programming Data Representation I/O: - (example) cprintf.c Memory: - memory address - stack / heap / constant space - basic data layout Pointer:
More informationCSE 374 Programming Concepts & Tools
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2017 Lecture 8 C: Miscellanea Control, Declarations, Preprocessor, printf/scanf 1 The story so far The low-level execution model of a process (one
More informationC Programming Multiple. Choice
C Programming Multiple Choice Questions 1.) Developer of C language is. a.) Dennis Richie c.) Bill Gates b.) Ken Thompson d.) Peter Norton 2.) C language developed in. a.) 1970 c.) 1976 b.) 1972 d.) 1980
More information[0569] p 0318 garbage
A Pointer is a variable which contains the address of another variable. Declaration syntax: Pointer_type *pointer_name; This declaration will create a pointer of the pointer_name which will point to the
More informationLanguage Reference Manual
ALACS Language Reference Manual Manager: Gabriel Lopez (gal2129) Language Guru: Gabriel Kramer-Garcia (glk2110) System Architect: Candace Johnson (crj2121) Tester: Terence Jacobs (tj2316) Table of Contents
More informationChapter 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= #
More information