MIDTERM TEST EESC 2031 Software Tools June 13, Last Name: First Name: Student ID: EECS user name: TIME LIMIT: 110 minutes
|
|
- Milo O’Connor’
- 6 years ago
- Views:
Transcription
1 MIDTERM TEST EESC 2031 Software Tools June 13, 2017 Last Name: First Name: Student ID: EECS user name: TIME LIMIT: 110 minutes This is a closed-book test. No books and notes are allowed. Extra space for answers can be found at the end of the test booklet. Assume that o size of char is 1 (byte); o size of short integer is 2 (bytes); o size of integer is 4 (bytes); o size of long integer is 8 (bytes); o size of float is 4 (bytes); o size of double is 8 (bytes); Also assume that the size of a pointer is 8 (bytes). Question Value Mark bonus TOTAL bonus Good Luck
2
3 Jun 13, 2017 (Tuesday) Name: Student ID: Page 3 of 15 Question 1 (14.5 pts) 1.1 (0.25 pt) For the following code fragment, what is the output of the printf() statement? int x = 9, y = 13, z = 3; printf("z: %d\n", z *= y + x + 2 ); z: (1 pt) What is the output of the printf() statement? int x = 2, y = x << 2; printf("%d %d %d %d\n", x, y, x y, x&y); (1 pt) What is the output of the printf() statement? int x = 13, y = z = 10; y = x++; z += y++; printf("x:%d y:%d z:%d\n", x,y,z); (1 pt) What is the output of the printf() statement? int x = 3; int y = 4; printf("%d %d %d %d\n", x y, x & y, x y, x && y); 1.5 (0.5 pt) What is the output of the printf() statement? int a = 6; int c = 4; float d = 1.1; short s =1; printf("x:%.3f y:%.3f\n", s*a/c*d, d/c*a*s); (0.5 pt) In 1.5, when d/c*a*s is evaluated, how many type conversions are performed? What is the type of the expression? three float 1.7 (0.5 pt) Recall that in ANSI-C, implicit type conversions are preformed on the following occasions 1) When the operands in an arithmetic or logical expression don t have the same type. 2) When the type of the expression on the right side of an assignment doesn t match the type of the variable on the left side.
4 3) When the type of an argument in a function call doesn t match the type of the corresponding parameter. 4) When the type of the expression in a return statement doesn t match the function s return type. On which of the above occasion(s), is type promotion performed, in which the type of the operand with the narrower type is converted to the type of the other operand? a. On 1) b. On 2) c. On 3) and 4) d. All of the above. 1.8 (1.5 pt) Consider the following ANSI-C program, where the programmer made typos on line 6 and 8, and also missed a else on line 8 #include <stdio.h> int main (){ int in; printf("enter an integer: "); scanf ("%d", &in); if (in = 1) /* this is line 6 */ printf("entered one\n"); if (in = 2) /* this is line 8 */ printf("entered two\n"); else printf("entered others\n"); return 0; What happens when you try to compile and run the program with input 2? (chose a. or b.) a. The program does not compile, because b. The program compiles, output is Entered one Entered two What happens when you try to compile and run the program with input 36? (chose a. or b.) a. The program does not compile b. The program compiles, output is Entered one Entered two What happens when you try to compile and run the program with input 1? (chose a. or b.) a. The program does not compile b. The program compiles, output is Entered one Entered two
5 Jun 13, 2017 (Tuesday) Name: Student ID: Page 5 of (0.25pt) Recall that a gcc compilation process contains three stages. The correct order is a. Linking Pre-processing Compiling b. Pre-processing Compiling Linking c. Compiling Pre-processing Linking d. None of the above 1.10 (1.5 pt) Consider the following statements. For each of the statements, if the right hand side of = is a valid integer literal in ANSI-C, then specify the decimal value of x. If the right hand side of = is not a valid integer literal, specify invalid. int x = b ; invalid int x = 014; int x = 0X3f; 63 int x = 032L; int x = 0xfFG; invalid int x = 0392; invalid 1.11 (3.75 pt) Suppose flags is an integer variable with some value. What happens to flags in each of the following 3 statements, in terms of turning on/off or keeping the bits of flags? Denote the right-most bit as bit 0, the 2 nd right-most bit as bit 1 1) flags = flags (1 << 6); turn on bit 6 (right most is bit 0), keep other bits 2) flags = flags ~(1 << 4); keep bit 4, turn on all other bits 3) flags = flags & 0177; keep right-most 7 bits, turn off all other bits In statement 1) and 2) above, can any of the parentheses be removed without affecting the meaning and value of the expression? If yes, specify which one(s) and briefly explain why. parenthesis in 1) can be removed. Because << has higher precedence than, so 1 << 6 is evaluated before anyway Now suppose you need an int mask whose binary representation is How do you declare it in ANSI-C code? List 3 ways of doing it. int mask = 41 int mask = 051 int mask = 0x29 Other slu: int mask = 1 <<5 1 << 3 1 int mask = 9 1 << 3 anything evaluated to 41 decimal What happens to flags in the following two statements, in terms of turning on/off or keeping bits of flags? Denote the right-most bit as bit 0, the 2 nd right-most as bit 1... flags = flags mask turn on bits 0, 3, 5, keep others flags = flags & mask keep bit 0, 3, 5, turn off all other bits
6 1.12 (1.25 pt) For each of the following array declaration and initializations, determine if the statement is legal in ANSI C. If it is illegal, write illegal. If it is legal, then list (the value of) all the elements in the array, separated by comma or space. int k[3] ={1,5,3,2,25; illegal int k[5] = {1; int k[6] = {1,4,5; int k[] ={1,5,3,2,25; int k2[] = k; illegal 1.13 (1.5 pt) Given the statement char messages[3][20] = {"Hello", "Hi", "There"; What is the value of sizeof(messages)? 3 * 20 * 1 = 60 (bytes) write a single C statement to change "Hi" to "How are you" strcpy (messages[1], How are you ) or sprintf(messages[1], %s, How are you ) or sprintf(messages[1], How are you ) write a single C statement to change 'h' in "There" to 'H' messages [2][1] = H or messages[2][1] =toupper(messages[2][1]); Question 2 (12 pt) 2.1 (1 pt) Consider the following ANSI C program. #include<stdio.h> void afunction (float input){ input = input * 2.0; int main(){ float input; scanf("%f", &input); afunction(input); printf("%.3f\n", input); Now suppose the program compiles and the user enters 7.4 What is the output of the program? Call by value. The formal argument of function happens to have the same name as the actual argument but they are two variables. The former is a copy of the latter.
7 Jun 13, 2017 (Tuesday) Name: Student ID: Page 7 of (1 pt) Consider the following function definition in ANSI C. /* this function initializes argument array arr s first n elements to 0 */ void cleararr (int arr[], int n){ int index; while (index < n){ arr[index++] = 0; Do you think that this function will work as expected? Yes No. The reason is: index is a local variable, which is initialized by the compiler to a garbage value, not 0 need to initialize to 0 explicitly. 2.3 (1pt) Consider the following ANSI C program. #include<stdio.h> #define N 4 void afun(); int main(int argc, char *argv[]) { int k; for(k=0; k<n; k++) afun(); return 0; void afun(){ int static counter; int y = ++counter; printf("%d ", y); What are the outputs of the program? (1 pt) Describe the usage(s) of key word static for global variable in ANSI-C. Limit the scope to the file in which it is defined. That is, make it not accessible to the other files.
8 2.5 (2pt) Consider the following ANSI C program. #define N 4 #define INCRE(x) x * x * x #define DECRE(x) x / 2 int main(){ When you invoke the pre-processor, using gcc -E, what is the pre-processed code of main, i.e., the output generated by the preprocessor (and sent as input to the compiler)? /* use marcos */ int i = N + 6; int j = DECRE(i); int k = INCRE(j + 10); int main(){ int i = 4 + 6; int j = i / 2; int k = j + 10 * j + 10 * j + 10 Now we compile and run the program. At the end of main, what is the value of i, j and k? i: 10 j: 5 k: (1.5pt) What are the outputs of the 2 printf() statements in the following code fragment? char msg [] = "Hello"; printf("%d %d", sizeof(msg), strlen(msg)); char msg2[10] = "Hello"; printf("%d %d", sizeof(msg2), strlen(msg2)); (1.5pt) What are the outputs of the 2 printf() statements in the following code fragment? char msg [] = "Hello the world"; printf("%s %d %d", msg, sizeof(msg), strlen(msg)); strcpy(msg, "Hi"); Hello the world printf("%s %d %d", msg, sizeof(msg), strlen(msg)); Hi 16 2
9 Jun 13, 2017 (Tuesday) Name: Student ID: Page 9 of (3 pt) Consider the following ANSI C program. int main(){ char name[60]; int age; float wage; printf("enter name, age and wage: "); scanf("%s %d %f", name, &age, &wage); Explain briefly: printf("%s %d %f", name, age, wage); Briefly explain: Why does function scanf() require the use of & for age and wage (i.e., &age and &wage)? (FYI: if you use age and wage without &,you get segmentation fault and the program crashes.) Scanf needs to change the value of its parameter. Since c is call/pass by value, to change/set the value of age and wage, scanf needs the address/pointer of the variables, and thus &age, &wage. Why don t we need to use & for name in scanf()? (FYI: the program won t compile if you use &name.) In C, array name contains the address of the first elements arr=&arr[0]. So we just pass it to the function without & (actually it is wrong to pass & for arrays) Why don t we need & for age and wage in printf()? To output the values of age and wage (rather than changing them), pass-by-value is sufficient. Just get a copy of the values of age and wage and output them. Question 3 Pointers and arrays ( pt) 3.1 (4 pt) Compete the following program so that the output of main is a: 600 b:18. That is, values of a and b are swapped and then the swapped values are doubled.
10 /* This function double the pointee of arguments, and then call another function to swap the (doubled) values */ void increswap(int *px, int *py) { /* double the values of pointees of px and py */ * px *=2; * py *=2; /* now call function swap() to swap the pointees. swap( px, py ); /* this function swap the pointees of the two pointers */ void swap ( int *p1, int *p2 ) { int tmp = *p1; *p1 = *p2; *p2 = tmp; void main( ) { int a=9, b=300; increswap( &a, &b ); printf("a:%d b:%d", a, b); /* should get a:600 b:18 */ 3.2 (2 pt) What is the output of the following ANSI C program? #include<stdio.h> main(){ What are the two types of testing method and what are the main differences? int x = 199, y = 22; int *ip, *ip2,**pip; ip = &x; pip = &ip; ip2 = ip; y = **pip; (*ip2) *= 10; ip = &y; (** pip)++; (*ip2) -= 10; printf("x:%d y:%d\n", x,y); x: 1980 y: 200
11 Jun 13, 2017 (Tuesday) Name: Student ID: Page 11 of (1.5 pt) Consider the following ANSI C code fragment. int arr [] = {1,2,3,4,5,6; int * p = arr; int i = arr[3]; In addition to arr[3], what are the other ways to access the same element of arr? List 3 ways. int i = *(p + 3) int i = * (arr + 3) int i = p[3] 3.4 (2.25 pt) Consider the following ANSI C program. main(){ int i; int * pint = &i; char c; char * pchar = &c; double d; double * pdouble= &d; printf("%p %p %p\n", pchar, pint, pdouble); /* line 4 */ printf("%p %p %p\n", pchar+1, pint+1, pdouble+1); /* line 5 */ pint++; pchar++; pdouble++; printf("%p %p %p\n", pchar, pint, pdouble); /* line 7 */ pint += 4; pchar += 4; pdouble +=4; printf("%p %p %p\n", pchar, pint, pdouble); /* line 9 */ Suppose the output of the first printf (line 4) is (Recall that printing a pointer directly with %p outputs the content/value of the pointer, which is the address of its pointee, in Hex. To simplify, here we assume it prints in decimal) What is the output of the second printf (line 5)? What is the output of the third printf (line 7)? What is the output of the fourth printf (line 9)?
12 3.5 (2.5 pt) Given the following declaration statements in ANSI C, int arr[]={1,2,3,4,5,6; int * ptr = arr; int i; Specify if each line of (independent) statement below is valid or invalid int * ptr = arr + 3; valid invalid int * ptr = &arr[0] valid invalid i = ptr arr; valid invalid i = ptr + arr; valid invalid i = * (ptr + 2); valid invalid arr++; valid invalid *(arr + 4)=2; valid invalid ptr ++; valid invalid ptr --; valid invalid i = ptr > arr; valid invalid 3.6 (6 pt) Given the following ANSI C program, and assume that the first element of arr is stored in memory address 2000; What is the output of each printf( ) statement? (Recall that %p is used to print the content/value of the pointer, which is the address of its pointee. Here we assume it prints in decimal) main() { int arr[] = {17, 3, 58, 10, 126, 22, 35, 140, 165, 190; int *p = arr; int *q; printf("%p %p %d\n", arr, p, *p); printf("%p %d\n", p+4,*(p+4) ); p; printf("%p %d\n", p, *p); p = arr + 5; printf("%p %d\n", p, *(p + 2)); q = p; p = q +3; printf ("%p %p %d %d %d\n", p, q, p-q, *p, *q); (*p)++; printf("%d %d\n", *(arr+4), *(arr + 8) );
13 Jun 13, 2017 (Tuesday) Name: Student ID: Page 13 of (1.5 pt) For a function that expects a char array as its argument, its prototype can be either void processarr (char []) or void processarr (char *). True False Assume the following ANSI C code fragment int main(){ char msg[] = "Hello the World"; char * p = msg; processarr ( ); /* line 4 */ void processarr (char []){. Which of the following could be a valid function call to processarr in line 4 a. proceeearr(&msg[2]); b. processarr(p); c. processarr(&p[0]); d. processarr(msg+3); e. All of the above 3.8 (2.5+1 bonus) Consider the following ANSI C code, assume that the first element of msg has starting address 1000; what are the outputs of the three printf statements? Recall that %p prints the content of a pointer variable, and here we assume it prints in decimal. main(){ char msg[] = "HelloWorld"; printf("%s %p %d %d\n", msg, msg, sizeof(msg), strlen(msg)); processarray(msg); HelloWorld processarray2(msg); void processarray (char c []){ printf("%s %p %d %d\n", c, c, sizeof(c), strlen(c)); HelloWorld void processarray2 (char * c){ printf("%s %p %d %d\n", c, c, sizeof(c), strlen(c)); HelloWorld
14 3.9 (1.25pt) Consider the following ANSI C program. int main(){ int a[]={2,4,6, 8,10; int resu = dosthrecursively(a, 5); printf("%d\n", resu); return 0; int dosthrecursively(int* c, int n){ if (n==1) return *c; else return *c + dosthrecursively(c+1, n-1); What is the output of the first printf() in main(), or, explain what does function dosthrecursively intend to do? Sum up first n elements in the array c = (0.5 pt Bonus) As mentioned in the textbook and class, the declaration of a pointer related variable is intended as a mnemonic (means help you memorize ). For example, declaration int * ptr; can be interpreted as "expression * ptr is an int (and thus ptr is an integer pointer). Based on this rule, guess what the following statements declare. That is, what is the type that ptr is declared to be? You can draw pictures if you like. (We will talk about this next week in class.) int * ptr []; ptr is an array. Each element of the array is a pointer to integer. That is, ptr is an array of (int) pointers ptr int int * ptr [3] (END of TEST)
15 Jun 13, 2017 (Tuesday) Name: Student ID: Page 15 of 15 Operator precedence (from high to low) and associativity. (You can detach this page, and use it for scratch work )
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 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 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 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 informationDynamic 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 informationProcedural 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 informationFundamental 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 informationArrays 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 informationLecture 04 Introduction to pointers
Lecture 04 Introduction to pointers A pointer is an address in the memory. One of the unique advantages of using C is that it provides direct access to a memory location through its address. A variable
More informationArrays 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 informationSU 2017 May 18/23 LAB 3 Bitwise operations, Program structures, Functions (pass-by-value), local vs. global variables. Debuggers
SU 2017 May 18/23 LAB 3 Bitwise operations, Program structures, Functions (pass-by-value), local vs. global variables. Debuggers 1. Problem A Pass-by-value, and trace a program with debugger 1.1 Specification
More information10/20/2015. Midterm Topic Review. Pointer Basics. C Language III. CMSC 313 Sections 01, 02. Adapted from Richard Chang, CMSC 313 Spring 2013
Midterm Topic Review Pointer Basics C Language III CMSC 313 Sections 01, 02 1 What is a pointer? Why Pointers? Pointer Caution pointer = memory address + type A pointer can contain the memory address of
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 informationCS113: Lecture 5. Topics: Pointers. Pointers and Activation Records
CS113: Lecture 5 Topics: Pointers Pointers and Activation Records 1 From Last Time: A Useless Function #include void get_age( int age ); int age; get_age( age ); printf( "Your age is: %d\n",
More informationOnline Judge and C. Roy Chan. January 12, Outline Information Online Judge Introduction to C. CSC2100B Data Structures Tutorial 1
Roy Chan CSC2100B Data Structures Tutorial 1 January 12, 2009 1 / 38 1 Information Your TA team Course Information Assignment 2 Online Judge Writing Your Assignment Program Submitting Your Program Online
More informationChapter 11 Introduction to Programming in C
C: A High-Level Language Chapter 11 Introduction to Programming in C Original slides from Gregory Byrd, North Carolina State University Modified slides by Chris Wilcox, Colorado State University! Gives
More informationArrays and Pointers (part 1)
Arrays and Pointers (part 1) CSE 2031 Fall 2012 Arrays Grouping of data of the same type. Loops commonly used for manipulation. Programmers set array sizes explicitly. Arrays: Example Syntax type name[size];
More informationMidterm Exam 2 Solutions C Programming Dr. Beeson, Spring 2009
Midterm Exam 2 Solutions C Programming Dr. Beeson, Spring 2009 April 16, 2009 Instructions: Please write your answers on the printed exam. Do not turn in any extra pages. No interactive electronic devices
More informationParameter passing. Programming in C. Important. Parameter passing... C implements call-by-value parameter passing. UVic SEng 265
Parameter passing Programming in C UVic SEng 265 Daniel M. German Department of Computer Science University of Victoria 1 SEng 265 dmgerman@uvic.ca C implements call-by-value parameter passing int a =
More information3/22/2016. Pointer Basics. What is a pointer? C Language III. CMSC 313 Sections 01, 02. pointer = memory address + type
Pointer Basics What is a pointer? pointer = memory address + type C Language III CMSC 313 Sections 01, 02 A pointer can contain the memory address of any variable type A primitive (int, char, float) An
More informationChapter 11 Introduction to Programming in C
Chapter 11 Introduction to Programming in C Original slides from Gregory Byrd, North Carolina State University Modified by Chris Wilcox, Yashwant Malaiya Colorado State University C: A High-Level Language
More informationCMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 13, FALL 2012
CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 13, FALL 2012 TOPICS TODAY Project 5 Pointer Basics Pointers and Arrays Pointers and Strings POINTER BASICS Java Reference In Java,
More informationBinary Representation. Decimal Representation. Hexadecimal Representation. Binary to Hexadecimal
Decimal Representation Binary Representation Can interpret decimal number 4705 as: 4 10 3 + 7 10 2 + 0 10 1 + 5 10 0 The base or radix is 10 Digits 0 9 Place values: 1000 100 10 1 10 3 10 2 10 1 10 0 Write
More informationDecimal Representation
Decimal Representation Can interpret decimal number 4705 as: 4 10 3 + 7 10 2 + 0 10 1 + 5 10 0 The base or radix is 10 Digits 0 9 Place values: 1000 100 10 1 10 3 10 2 10 1 10 0 Write number as 4705 10
More informationUnited States Naval Academy Electrical and Computer Engineering Department EC310-6 Week Midterm Spring AY2017
United States Naval Academy Electrical and Computer Engineering Department EC310-6 Week Midterm Spring AY2017 1. Do a page check: you should have 8 pages including this cover sheet. 2. You have 50 minutes
More informationChapter 11 Introduction to Programming in C
Chapter 11 Introduction to Programming in C Original slides from Gregory Byrd, North Carolina State University Modified slides by Chris Wilcox, Colorado State University C: A High-Level Language! Gives
More informationChapter 11 Introduction to Programming in C
Chapter 11 Introduction to Programming in C C: A High-Level Language Gives symbolic names to values don t need to know which register or memory location Provides abstraction of underlying hardware operations
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 informationArrays and Pointers. CSC209: Software Tools and Systems Programming (Winter 2019) Furkan Alaca & Paul Vrbik. University of Toronto Mississauga
Arrays and Pointers CSC209: Software Tools and Systems Programming (Winter 2019) Furkan Alaca & Paul Vrbik University of Toronto Mississauga https://mcs.utm.utoronto.ca/~209/ Week 2 Alaca & Vrbik (UTM)
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 informationArrays in C. Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. Indian Institute of Technology Kharagpur. Basic Concept
Arrays in C Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. Indian Institute of Technology Kharagpur 1 Basic Concept Many applications require multiple data items that have common characteristics.
More informationC0MP1911 Final Exam 1337 Computing 1
Family Name: Other Names: Signature: Student Number: This PAPER is NOT to be retained by the STUDENT The University Of New South Wales C0MP1911 Final Exam 1337 Computing 1 July 2006 Time allowed: 3 hrs
More informationUnited States Naval Academy Electrical and Computer Engineering Department EC310-6 Week Midterm Spring 2015
United States Naval Academy Electrical and Computer Engineering Department EC310-6 Week Midterm Spring 2015 1. Do a page check: you should have 8 pages including this cover sheet. 2. You have 50 minutes
More informationCS 0449 Sample Midterm
Name: CS 0449 Sample Midterm Multiple Choice 1.) Given char *a = Hello ; char *b = World;, which of the following would result in an error? A) strlen(a) B) strcpy(a, b) C) strcmp(a, b) D) strstr(a, b)
More informationIntroduction 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 informationC BOOTCAMP DAY 2. CS3600, Northeastern University. Alan Mislove. Slides adapted from Anandha Gopalan s CS132 course at Univ.
C BOOTCAMP DAY 2 CS3600, Northeastern University Slides adapted from Anandha Gopalan s CS132 course at Univ. of Pittsburgh Pointers 2 Pointers Pointers are an address in memory Includes variable addresses,
More informationCMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 13, SPRING 2013
CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 13, SPRING 2013 TOPICS TODAY Reminder: MIDTERM EXAM on THURSDAY Pointer Basics Pointers & Arrays Pointers & Strings Pointers & Structs
More informationDynamic Memory Allocation and Command-line Arguments
Dynamic Memory Allocation and Command-line Arguments CSC209: Software Tools and Systems Programming Furkan Alaca & Paul Vrbik University of Toronto Mississauga https://mcs.utm.utoronto.ca/~209/ Week 3
More informationMidterm Exam Nov 8th, COMS W3157 Advanced Programming Columbia University Fall Instructor: Jae Woo Lee.
Midterm Exam Nov 8th, 2012 COMS W3157 Advanced Programming Columbia University Fall 2012 Instructor: Jae Woo Lee About this exam: - There are 4 problems totaling 100 points: problem 1: 30 points problem
More informationNote: unless otherwise stated, the questions are with reference to the C Programming Language. You may use extra sheets if need be.
CS 156 : COMPUTER SYSTEM CONCEPTS TEST 1 (C PROGRAMMING PART) FEBRUARY 6, 2001 Student s Name: MAXIMUM MARK: 100 Time allowed: 45 minutes Note: unless otherwise stated, the questions are with reference
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 information3. EXPRESSIONS. It is a sequence of operands and operators that reduce to a single value.
3. EXPRESSIONS It is a sequence of operands and operators that reduce to a single value. Operator : It is a symbolic token that represents an action to be taken. Ex: * is an multiplication operator. Operand:
More informationCOMPUTER APPLICATION
Total No. of Printed Pages 16 HS/XII/A.Sc.Com/CAP/14 2 0 1 4 COMPUTER APPLICATION ( Science / Arts / Commerce ) ( Theory ) Full Marks : 70 Time : 3 hours The figures in the margin indicate full marks for
More informationPointers and Structure. Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island
Pointers and Structure Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island 1 Pointer Variables Each variable in a C program occupies space in
More informationChapter 11 Introduction to Programming in C
C: A High-Level Language Chapter 11 Introduction to Programming in C Original slides from Gregory Byrd, North Carolina State University Modified slides by Chris Wilcox, Colorado State University Gives
More informationChapter 3: Arrays and More C Functionality
Chapter 3: Arrays and More C Functionality Objectives: (a) Describe how an array is stored in memory. (b) Define a string, and describe how strings are stored. (c) Describe the implications of reading
More informationArrays and Pointers (part 1)
Arrays and Pointers (part 1) CSE 2031 Fall 2010 17 October 2010 1 Arrays Grouping of data of the same type. Loops commonly used for manipulation. Programmers set array sizes explicitly. 2 1 Arrays: Example
More informationArrays. Example: Run the below program, it will crash in Windows (TurboC Compiler)
1 Arrays General Questions 1. What will happen if in a C program you assign a value to an array element whose subscript exceeds the size of array? A. The element will be set to 0. B. The compiler would
More informationChapter 11 Introduction to Programming in C
Chapter 11 Introduction to Programming in C C: A High-Level Language Gives symbolic names to values don t need to know which register or memory location Provides abstraction of underlying hardware operations
More informationApplied Programming and Computer Science, DD2325/appcs15 PODF, Programmering och datalogi för fysiker, DA7011
Applied Programming and Computer Science, DD2325/appcs15 PODF, Programmering och datalogi för fysiker, DA7011 Autumn 2015 Lecture 3, Simple C programming M. Eriksson (with contributions from A. Maki and
More informationCSE101-lec#12. Designing Structured Programs Introduction to Functions. Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU
CSE101-lec#12 Designing Structured Programs Introduction to Functions Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU Outline Designing structured programs in C: Counter-controlled repetition
More informationProgramming for Engineers Iteration
Programming for Engineers Iteration ICEN 200 Spring 2018 Prof. Dola Saha 1 Data type conversions Grade average example,-./0 class average = 23450-67 893/0298 Grade and number of students can be integers
More informationGovernment Polytechnic Muzaffarpur.
Government Polytechnic Muzaffarpur. Name of the Lab: COMPUTER PROGRAMMING LAB (MECH. ENGG. GROUP) Subject Code: 1625408 Experiment: 1 Aim: Programming exercise on executing a C program. If you are looking
More informationPointers. Pointer Variables. Chapter 11. Pointer Variables. Pointer Variables. Pointer Variables. Declaring Pointer Variables
Chapter 11 Pointers The first step in understanding pointers is visualizing what they represent at the machine level. In most modern computers, main memory is divided into bytes, with each byte capable
More informationCSCI-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 informationPointers. Pointers. Pointers (cont) CS 217
Pointers CS 217 Pointers Variables whose values are the addresses of variables Operations address of (reference) & indirection (dereference) * arithmetic +, - Declaration mimics use char *p; *p is a char,
More informationECE264 Fall 2013 Exam 1, September 24, 2013
ECE264 Fall 2013 Exam 1, September 24, 2013 In signing this statement, I hereby certify that the work on this exam is my own and that I have not copied the work of any other student while completing it.
More informationOperators and Expressions:
Operators and Expressions: Operators and expression using numeric and relational operators, mixed operands, type conversion, logical operators, bit operations, assignment operator, operator precedence
More informationC Programming
204216 -- C Programming Chapter 3 Processing and Interactive Input Adapted/Assembled for 204216 by Areerat Trongratsameethong A First Book of ANSI C, Fourth Edition Objectives Assignment Mathematical Library
More informationLAB 6 (2017 June 22/27) Array of pointers. Dynamic memory allocation.
LAB 6 (2017 June 22/27) Array of pointers. Dynamic memory allocation. Due: June 30 (Fri) 11:59 pm Part I Array of pointers vs. 2D arrays. Command line arguments. 1. Problem A Motivation In class lots people
More informationM4.1-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE
M4.1-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE NOTE: 1. There are TWO PARTS in this Module/Paper. PART ONE contains FOUR questions and PART TWO contains FIVE questions. 2. PART ONE is to be
More informationCS16 Exam #1 7/17/ Minutes 100 Points total
CS16 Exam #1 7/17/2012 75 Minutes 100 Points total Name: 1. (10 pts) Write the definition of a C function that takes two integers `a` and `b` as input parameters. The function returns an integer holding
More informationME964 High Performance Computing for Engineering Applications
ME964 High Performance Computing for Engineering Applications Quick Overview of C Programming January 20, 2011 Dan Negrut, 2011 ME964 UW-Madison There is no reason for any individual to have a computer
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 informationOutline. 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 informationPractice Sheet #07 with Solutions
Department of Computer Science & Engineering Indian Institute of Technology Kharagpur Practice Sheet #07 with Solutions Topic: Pointer in C Date: 23-02-2017 1 Assume the following C variable declaration
More informationCS 107 Lecture 2: Bits and Bytes (continued)
CS 107 Lecture 2: Bits and Bytes (continued) Friday, January 12, 2018 Computer Systems Winter 2018 Stanford University Computer Science Department Reading: Reader: Number Formats Used in CS 107 and Bits
More informationScheme G. Sample Test Paper-I. Course Name : Computer Engineering Group Course Code : CO/CD/CM/CW/IF Semester : Second Subject Tile : Programming in C
Sample Test Paper-I Marks : 25 Time:1 Hrs. Q1. Attempt any THREE 09 Marks a) State four relational operators with meaning. b) State the use of break statement. c) What is constant? Give any two examples.
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 informationComputer Programming. C Array is a collection of data belongings to the same data type. data_type array_name[array_size];
Arrays An array is a collection of two or more adjacent memory cells, called array elements. Array is derived data type that is used to represent collection of data items. C Array is a collection of data
More informationCS113: Lecture 3. Topics: Variables. Data types. Arithmetic and Bitwise Operators. Order of Evaluation
CS113: Lecture 3 Topics: Variables Data types Arithmetic and Bitwise Operators Order of Evaluation 1 Variables Names of variables: Composed of letters, digits, and the underscore ( ) character. (NO spaces;
More informationSU 2017 May 11/16 LAB 2: Character and integer literals, number systems, character arrays manipulation, relational operator
SU 2017 May 11/16 LAB 2: Character and integer literals, number systems, character arrays manipulation, relational operator 0 Problem 0 number bases Visit the website www.cleavebooks.co.uk/scol/calnumba.htm
More informationConditional Statement
Conditional Statement 1 Conditional Statements Allow different sets of instructions to be executed depending on truth or falsity of a logical condition Also called Branching How do we specify conditions?
More informationEC312 Chapter 4: Arrays and Strings
Objectives: (a) Describe how an array is stored in memory. (b) Define a string, and describe how strings are stored. EC312 Chapter 4: Arrays and Strings (c) Describe the implications of reading or writing
More informationWhy Pointers. Pointers. Pointer Declaration. Two Pointer Operators. What Are Pointers? Memory address POINTERVariable Contents ...
Why Pointers Pointers They provide the means by which functions can modify arguments in the calling function. They support dynamic memory allocation. They provide support for dynamic data structures, such
More informationFundamental 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 informationChapter 12 Variables and Operators
Chapter 12 Variables and Operators Basic C Elements Variables Named, typed data items Operators Predefined actions performed on data items Combined with variables to form expressions, statements Statements
More informationInformation Science 1
Topics covered Information Science 1 Terms and concepts from Week 8 Simple calculations Documenting programs Simple Calcula,ons Expressions Arithmetic operators and arithmetic operator precedence Mixed-type
More informationExercise Session 2 Simon Gerber
Exercise Session 2 Simon Gerber CASP 2014 Exercise 2: Binary search tree Implement and test a binary search tree in C: Implement key insert() and lookup() functions Implement as C module: bst.c, bst.h
More informationPhysics 2660: Fundamentals of Scientific Computing. Lecture 3 Instructor: Prof. Chris Neu
Physics 2660: Fundamentals of Scientific Computing Lecture 3 Instructor: Prof. Chris Neu (chris.neu@virginia.edu) Announcements Weekly readings will be assigned and available through the class wiki home
More informationComputer Science & Information Technology (CS) Rank under AIR 100. Examination Oriented Theory, Practice Set Key concepts, Analysis & Summary
GATE- 2016-17 Postal Correspondence 1 C-Programming Computer Science & Information Technology (CS) 20 Rank under AIR 100 Postal Correspondence Examination Oriented Theory, Practice Set Key concepts, Analysis
More informationPointers. Part VI. 1) Introduction. 2) Declaring Pointer Variables. 3) Using Pointers. 4) Pointer Arithmetic. 5) Pointers and Arrays
EE105: Software Engineering II Part 6 Pointers page 1 of 19 Part VI Pointers 1) Introduction 2) Declaring Pointer Variables 3) Using Pointers 4) Pointer Arithmetic 5) Pointers and Arrays 6) Pointers and
More informationFORM 2 (Please put your name and form # on the scantron!!!!)
CS 161 Exam 2: FORM 2 (Please put your name and form # on the scantron!!!!) True (A)/False(B) (2 pts each): 1. Recursive algorithms tend to be less efficient than iterative algorithms. 2. A recursive function
More informationEM108 Software Development for Engineers
EE108 Section 6 Pointers page 1 of 20 EM108 Software Development for Engineers Section 6 - Pointers 1) Introduction 2) Declaring Pointer Variables 3) Using Pointers 4) Pointer Arithmetic 5) Pointers and
More informationC-Programming. CSC209: Software Tools and Systems Programming. Paul Vrbik. University of Toronto Mississauga
C-Programming CSC209: Software Tools and Systems Programming Paul Vrbik University of Toronto Mississauga https://mcs.utm.utoronto.ca/~209/ Adapted from Dan Zingaro s 2015 slides. Week 2.0 1 / 19 What
More informationPointers and Arrays 1
Pointers and Arrays 1 Pointers and Arrays When an array is declared, The compiler allocates sufficient amount of storage to contain all the elements of the array in contiguous memory locations The base
More informationCSCI 2132 Final Exam Solutions
Faculty of Computer Science 1 CSCI 2132 Final Exam Solutions Term: Fall 2018 (Sep4-Dec4) 1. (12 points) True-false questions. 2 points each. No justification necessary, but it may be helpful if the question
More informationLecture 3. More About C
Copyright 1996 David R. Hanson Computer Science 126, Fall 1996 3-1 Lecture 3. More About C Programming languages have their lingo Programming language Types are categories of values int, float, char Constants
More informationBSM540 Basics of C Language
BSM540 Basics of C Language Chapter 4: Character strings & formatted I/O Prof. Manar Mohaisen Department of EEC Engineering Review of the Precedent Lecture To explain the input/output functions printf()
More informationCOMP 2001/2401 Test #1 [out of 80 marks]
COMP 2001/2401 Test #1 [out of 80 marks] Duration: 90 minutes Authorized Memoranda: NONE Note: for all questions, you must show your work! Name: Student#: 1. What exact shell command would you use to:
More informationMultiple Choice Questions ( 1 mark)
Multiple Choice Questions ( 1 mark) Unit-1 1. is a step by step approach to solve any problem.. a) Process b) Programming Language c) Algorithm d) Compiler 2. The process of walking through a program s
More informationLearning C Language. For BEGINNERS. Remember! Practice will make you perfect!!! :D. The 6 th week / May 24 th, Su-Jin Oh
Remember! Practice will make you perfect!!! :D Learning C Language For BEGINNERS The 6 th week / May 24 th, 26 Su-Jin Oh sujinohkor@gmail.com 1 Index Basics Operator Precedence Table and ASCII Code Table
More informationLecture 8: Pointer Arithmetic (review) Endianness Functions and pointers
CSE 30: Computer Organization and Systems Programming Lecture 8: Pointer Arithmetic (review) Endianness Functions and pointers Diba Mirza University of California, San Diego 1 Q: Which of the assignment
More informationFor questions 4 through 7, select the value assigned to the relevant variable, given the declarations: 3) ) This is not allowed
This homework assignment focuses primarily on some of the basic syntax and semantics of C. The answers to the following questions can be determined by consulting a C language reference and/or writing short
More informationC: 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 informationBristol Institute of Technology
Bristol Institute of Technology Academic Year: 09/10 Module Leader: Module Code: Title of Module: Ian Johnson UFCETS-20-1 Programming in C Examination Date: Monday 12 th January 2009 Examination Start
More informationArrays, Pointers and Memory Management
Arrays, Pointers and Memory Management EECS 2031 Summer 2014 Przemyslaw Pawluk May 20, 2014 Answer to the question from last week strct->field Returns the value of field in the structure pointed to by
More informationPROGRAMMAZIONE I A.A. 2017/2018
PROGRAMMAZIONE I A.A. 2017/2018 A pointer is a variable whose value is the address of another variable, i.e., direct address of the memory location. DECLARING POINTERS POINTERS A pointer represents both
More informationComputers 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 informationFinal CSE 131B Spring 2004
Login name Signature Name Student ID Final CSE 131B Spring 2004 Page 1 Page 2 Page 3 Page 4 Page 5 Page 6 Page 7 Page 8 (25 points) (24 points) (32 points) (24 points) (28 points) (26 points) (22 points)
More information