Final Intro to C Review

Similar documents
COP 3223 Introduction to Programming with C - Study Union - Fall 2017

COP 3223 Introduction to Programming with C - Study Union - Spring 2018

COP 3223 Introduction to Programming with C - Study Union - Fall 2017

Memory Allocation. General Questions

High Performance Programming Programming in C part 1

Aryan College. Fundamental of C Programming. Unit I: Q1. What will be the value of the following expression? (2017) A + 9

C programming basics T3-1 -

Principles of C and Memory Management

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

Arrays, Pointers and Memory Management

C Pointers. Abdelghani Bellaachia, CSCI 1121 Page: 1

Signature: ECE 551 Midterm Exam

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

Kurt Schmidt. October 30, 2018

Procedural programming with C

Subject: Fundamental of Computer Programming 2068

CS 0449 Sample Midterm

This exam is to be taken by yourself with closed books, closed notes, no calculators.

Arrays. An array is a collection of several elements of the same type. An array variable is declared as array name[size]

ESC101N: Fundamentals of Computing End-sem st semester

Midterm #2 With Solutions solutions in blue marking notes in red

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

COP 3223 Final Review

Parameter passing. Programming in C. Important. Parameter passing... C implements call-by-value parameter passing. UVic SEng 265

a) (5 points) What is the output of the following code sequence? int *ptr = 0x1050; printf ("%x\n", ptr--); printf ("%x\n", ptr);

Fundamental of Programming (C)

Compiling and Running a C Program in Unix

CSE 5A Final Fall 2006

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

SOFTWARE Ph.D. Qualifying Exam Spring Consider the following C program which consists of two function definitions including the main function.

Arrays and Pointers (part 1)

Advanced Pointer Topics

COP 3223 Final Review

INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR Stamp / Signature of the Invigilator

Arrays and Pointers (part 1)

Chapter 5. Section 5.4 The Common String Library Functions. CS 50 Hathairat Rattanasook

C Programming Basics II

Memory. What is memory? How is memory organized? Storage for variables, data, code etc. Text (Code) Data (Constants) BSS (Global and static variables)

Arrays and Pointers. CSE 2031 Fall November 11, 2013

High-performance computing and programming Intro to C on Unix/Linux. Uppsala universitet

advanced data types (2) typedef. today advanced data types (3) enum. mon 23 sep 2002 defining your own types using typedef

Problem 2 Add the two 2 s complement signed 8-bit values given below, and express your answer in decimal.

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

COMS W3101 Programming Language: C++ (Fall 2015) Ramana Isukapalli

C BOOTCAMP DAY 2. CS3600, Northeastern University. Alan Mislove. Slides adapted from Anandha Gopalan s CS132 course at Univ.

Pointers, Arrays, and Strings. CS449 Spring 2016

Linked-List Basic Examples. A linked-list is Linear collection of self-referential class objects, called nodes Connected by pointer links

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

The C Programming Language Part 4. (with material from Dr. Bin Ren, William & Mary Computer Science, and

ECE264 Spring 2013 Exam 1, February 14, 2013

ENEE150 Final Exam Review

#include <stdio.h> int main() { char s[] = Hsjodi, *p; for (p = s + 5; p >= s; p--) --*p; puts(s); return 0;

Pointers. Part VI. 1) Introduction. 2) Declaring Pointer Variables. 3) Using Pointers. 4) Pointer Arithmetic. 5) Pointers and Arrays

ECE264 Spring 2013 Final Exam, April 30, 2013

EM108 Software Development for Engineers

Floating-point lab deadline moved until Wednesday Today: characters, strings, scanf Characters, strings, scanf questions clicker questions

Library Functions. General Questions

2. Which of the following will print the value 2 for the above code?

UNIVERSITY OF WINDSOR Fall 2007 QUIZ # 2 Solution. Examiner : Ritu Chaturvedi Dated :November 27th, Student Name: Student Number:

CSE 333 Midterm Exam 2/14/14

C LANGUAGE A Short Course

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

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

Characters in C consist of any printable or nonprintable character in the computer s character set including lowercase letters, uppercase letters,

211: Computer Architecture Summer 2016

CS 61c: Great Ideas in Computer Architecture

CS Introduction to Programming Midterm Exam #2 - Prof. Reed Fall 2015

SOFTWARE Ph.D. Qualifying Exam Fall 2017

PRINCIPLES OF OPERATING SYSTEMS

Final Exam 1 /12 2 /12 3 /10 4 /7 5 /4 6 /10 7 /8 8 /9 9 /8 10 /11 11 /8 12 /10 13 /9 14 /13 15 /10 16 /10 17 /12. Faculty of Computer Science

A Crash Course in C. Steven Reeves

ECE551 Midterm Version 1

ECE264 Fall 2013 Exam 3, November 20, 2013

ECE551 Midterm Version 2

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

return return else return

2/28/2018. Overview. The C Programming Language Part 4. Pointers. Pointers. Pointers. Pointers

(13-2) Dynamic Data Structures I H&K Chapter 13. Instructor - Andrew S. O Fallon CptS 121 (November 17, 2017) Washington State University

CSE 333 Midterm Exam 7/25/16 Sample Solution. Question 1. (10 points) Preprocessor. Suppose we have the following two files:

C Programming Language: C ADTs, 2d Dynamic Allocation. Math 230 Assembly Language Programming (Computer Organization) Thursday Jan 31, 2008

This is CS50. Harvard University Fall Quiz 0 Answer Key

ECE 15B COMPUTER ORGANIZATION

C Multiple Choice Questions and answers MCQ with Ans.

CS1100 Introduction to Programming

A3-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH 'C' LANGUAGE

Review Topics. Final Exam Review Slides

Pointers and File Handling

Sample Examination. Family Name:... Other Names:... Signature:... Student Number:...

ARRAYS(II Unit Part II)

CS360 Midterm 1 - February 21, James S. Plank. Put all answers on the answer sheet. In all of these questions, please assume the following:

mith College Computer Science CSC352 Week #7 Spring 2017 Introduction to C Dominique Thiébaut

Tutorial 7. Number Colour Black Brown Red Orange Yellow Green Blue Violet Gray White

Character Strings. String-copy Example

From Java to C. Thanks to Randal E. Bryant and David R. O'Hallaron (Carnegie-Mellon University) for providing the basis for these slides

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

Q1: /20 Q2: /30 Q3: /24 Q4: /26. Total: /100

CGS 3460 Summer 07 Midterm Exam

Language comparison. C has pointers. Java has references. C++ has pointers and references

Advanced C Programming and Introduction to Data Structures

else return for return

Transcription:

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 well 40 Multiple Choice in 50 Minutes

1. How long of a string can you have in a character array of length 10? 2. printf( < >, g[4]); What percent code would you use for this line of code? Assume g has already been declared and initialized as a 2D char array. a. %d b. %c c. %f d. %s 3. Choose the correct function signature. a. int a addnums (int x, int y) b. void x printstuff(void b) c. float dividenums (int, int) d. char change(int z, int b) 4. What is the output of this program? int x = 357, y = 109; swap(&y,&x); printf("%d %d", x, y); void swap (int *x, int *y) int temp; temp = *y; *x = *y; *y = temp;

5. True or false. This is a valid struct definition. typedef struct int age; char name[20]; float height; ; 6. What will happen if you try to write to a file that does not exist using the w mode? a. The compiler will create one for you. b. The function will return NULL. c. The program will not compile. d. None of the above. 7. Expected output? int i, array[5], a = 9, b = 1, c = 1; array[0] = 12; for(i = 1; i < 5; i++) array[i] = array[i - b] + a; a += a; b = c; printf("%d\n", array[4]);

8. Expected output? int main() int nums[2][4], i, j, t=15; for(i=0; i<2; i++) nums[i][3] = t; t+=2; for(j=0; j<3; j++) nums[i][j] = t; t-=3; printf("%d\n", nums[0][0]); printf("%d\n", nums[0][3]); printf("%d\n", nums[1][3]); 9. Which of these is a valid way to insert a string into a char array? (assume word is a character array of length 20) a. strcat( Bee, word); b. word[0] = B ; word[1] = e ; word[2] = e ; word[3] = \0 ; c. strcpy( Bee, word); d. None of the above 10. What is the expected output? int z = 27, *k = &z, b = *k; k = &b; z = *k * 3; z /= *k; *k /= z; k = &z; printf("z = %d\t*k = %d\tb = %d", z, *k, b);

11. Write a program that places the string anxiety into a char array just large enough for it, then prints out the string in reverse order. #include <stdio.h> #include <string.h> 12. Fill in the code so that you put the string Stress into a file called finals.txt. FILE *ofp; char str[10]; strcpy(str, "Stress"); ofp = fopen( ); fprintf( ); fclose( );

13. Expected Output? int r = 3, m = 7; m = z(r, m-r); printf("m = %d\n", m); int z(int m, int r) int z = 0, i; for(i = 0; i < r; i++) z+=m+r; return z; 14. What number will strlen return for this string? +---+ +---+ +---+ +---+ +---+ +-----+ C r u m b \0 +---+ +---+ +---+ +---+ +---+ +-----+ 15. Which of the following initializes all the elements of the array to 0? a. int nums[23] == 0; b. int nums[23] = 0; c. for(i = 0; i < 23; i++) nums[i] = i; d. b & c e. None of the above

16. What is the expected output? void w(int *x, int *g); void v(int y, int h); int t(int h, int y); int a = 2, b = 3; w(&a,&b); printf("a = %d, b = %d\n", a, b); v(b,a); printf("a = %d, b = %d\n", a, b); b = t(b,a); printf("a = %d, b = %d\n", a, b); void w(int *x, int *g) int temp = *g; *g = *x**g; *x += *g; return; void v(int y, int h) y *= h; h *= y; return; int t(int h, int y) h += y; y *= h; return y;

17. Based off of the following lines of code, fill in the struct. Any array lengths will be of length 10; #include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct hat ; shoe ; x ; flo ; o; o p; float y; strcpy(p.shoe[0], "Coolio"); scanf("%c", &p.hat[0]); printf("%d\n", p.x); p.flo = &y; 18. Using the function signature below, write a function that compares two integers and sets the smaller one = to 0 and returns. If the numbers are equal, return right away. void deathmatch (int *x, int *y)

19. Expected output? #include <stdio.h> #include <stdlib.h> int y(int a, int *b, int *c); void g(int *a, int *b, int *c); int main() int a = 8, b = 13, c = 7; g(&b, &c, &a); printf("%d %d %d \n", b, a, c); b = y(b, &a, &a); printf("%d %d %d \n", b, a, c); int y(int a, int *b, int *c) if(*c > *b) *c -= *b; return *c + *b / 2; else if(*c < *b) *b -= *c; return *b + *c / 2; else return a + *c * 2; void g(int *a, int *b, int *c) int y = *a, z = *c, j = *b; *a = z; *c = y; *b = j;

20. True or false. This function takes in a person struct pointer and successfully prints out its contents. void printperson(person *user) printf("%s\n", user.name); printf("%d\n", user.age); printf("%f\n", user.height); 21. What is this recursive function doing? int y(int x) if(x <= 1) return 1; return x * y(x-1); 22. How many times will bananas be printed? for(i = 0; i < 6; i++) for(i = 0; i < 3; i++) printf("bananas\n"); 23. Which of these successfully allocates an integer array of size 10? a. int *x = calloc(sizeof(int) * 10); b. int *x = malloc(10); c. int *x = calloc(10); d. int *x = malloc(sizeof(int) * 10); 24. What is this recursive function doing? int foo(x, y) if(y <= 1) return x; return x + foo(x, y - 1); 25. What is the output? int main() double i[20]; printf("%d", sizeof(i));

26. True or false. This program will allocate memory for a double array of size 5 and print out its 5 trash values. int main() int i; double *ar = calloc(5, sizeof(double)); for(i = 0; i < 5; i++) printf("array[%d] = %lf\n", i, ar[i]); free(ar);