ENEE150 Final Exam Review

Similar documents
Cpt S 122 Data Structures. Data Structures

Cpt S 122 Data Structures. Course Review Midterm Exam # 1

Subject: Fundamental of Computer Programming 2068

C Data Structures Stacks. Stack. push Adds a new node to the top of the stack

Linked List. April 2, 2007 Programming and Data Structure 1

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

Kurt Schmidt. October 30, 2018

CS561 Manju Muralidharan Priya Structures in C CS200 STRUCTURES. Manju Muralidharan Priya

Advanced C Programming and Introduction to Data Structures

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

Programming. Lists, Stacks, Queues

Dynamic Memory Allocation

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

Fundamentals of Programming Session 19

CMSC Introduction to Algorithms Spring 2012 Lecture 7

Arrays and Pointers (part 1)

Solution for Data Structure

Arrays and Pointers. CSE 2031 Fall November 11, 2013

Applied Programming and Computer Science, DD2325/appcs15 PODF, Programmering och datalogi för fysiker, DA7011

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

11 'e' 'x' 'e' 'm' 'p' 'l' 'i' 'f' 'i' 'e' 'd' bool equal(const unsigned char pstr[], const char *cstr) {

Computer Systems Lecture 9

Introduction to Data Structures. Systems Programming

Dynamic Data Structures. CSCI 112: Programming in C

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

Final Intro to C Review

EE 312 Fall 2018 Midterm 1 Version A October 10, 2018

Huawei Test 3. 1 A card is drawn from a pack of 52 cards. The probability of getting a queen of club or a king of heart is:

List, Stack and Queue Implementation

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

CS24 Week 4 Lecture 2

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

M3-R4: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE

C: Pointers. C: Pointers. Department of Computer Science College of Engineering Boise State University. September 11, /21

CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-1-0)

Memory Allocation. General Questions

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

File: /media/young/d1 (180713)/Work tive_tree_search/search_defs.h Page 1 of 1

Arrays and Pointers (part 1)

Outline. Computer programming. Usage of time and date functions. Date and Time: time.h. Date and Time: time.h. Time functions:

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

Computer programming. "An expert is a man who has made all the mistakes which can be made, in a narrow field." Niels Bohr

Algorithms, Data Structures, and Problem Solving

IMPORTANT QUESTIONS IN C FOR THE INTERVIEW

IV Unit Second Part STRUCTURES

What is recursion. WAP to find sum of n natural numbers using recursion (5)

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

Scheme G. Sample Test Paper-I. Course Name : Computer Engineering Group Course Code : CO/CD/CM/CW/IF Semester : Second Subject Tile : Programming in C

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

Arrays, Pointers and Memory Management

Lecture 7: Data Structures. EE3490E: Programming S1 2017/2018 Dr. Đào Trung Kiên Hanoi Univ. of Science and Technology

Archivo: /home/young/work/cordic/binary_tree_search/search_defs.h Página 1 de 1

CS240: Programming in C

! Mon, May 5, 2:00PM to 4:30PM. ! Closed book, closed notes, clean desk. ! Comprehensive (covers entire course) ! 30% of your final grade

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

ECE 2400 Computer Systems Programming Fall 2018 Topic 6: C Dynamic Allocation

.:: UNIT 4 ::. STACK AND QUEUE

MODULE 5: Pointers, Preprocessor Directives and Data Structures

ECE 15B COMPUTER ORGANIZATION

Unit IV & V Previous Papers 1 mark Answers

MODULE V: POINTERS & PREPROCESSORS

SYSC 2006 CD. Come to the PASS workshop with your mock exam complete. During the workshop you can work with other students to review your work.

CS 137 Part 5. Pointers, Arrays, Malloc, Variable Sized Arrays, Vectors. October 25th, 2017

CP2 Revision. theme: dynamic datatypes & data structures

Procedural programming with C

CS 241 Data Organization Binary Trees

Come to the PASS workshop with your mock exam complete. During the workshop you can work with other students to review your work.

In Java we have the keyword null, which is the value of an uninitialized reference type

CS 261 Data Structures. Introduction to C Programming

COMP26120: Linked List in C (2018/19) Lucas Cordeiro

C Multiple Choice Questions and answers MCQ with Ans.

Linear Structures. Linear Structure. Implementations. Array details. List details. Operations 2/10/2013

Q. 1 What will be the output of the following program? Justify your answer. [4] #include <stdio.h> main(){ int i=4, a[5]={1,2,3,4,5};

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

#06 More Structures LIFO FIFO. Contents. Queue vs. Stack 3. Stack Operations. Pop. Push. Stack Queue Hash table

(6-1) Basics of a Queue. Instructor - Andrew S. O Fallon CptS 122 (September 26, 2018) Washington State University

Answer all questions. Write your answers only in the space provided. Full marks = 50

CSE2301. Dynamic memory Allocation. malloc() Dynamic Memory Allocation and Structs

ESc101: (Linear, Circular, Doubly) Linked Lists, Stacks, Queues, Trees. Introduction to Linked Lists

Outline. Briefly review the last class Pointers and Structs Memory allocation Linked lists

15. Stacks and Queues

Dynamic Data Structures (II)

ch = argv[i][++j]; /* why does ++j but j++ does not? */

Variation of Pointers

Queues. A queue is a special type of structure that can be used to maintain data in an organized way.

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

Department of Computer Science & Engineering Indian Institute of Technology Kharagpur. Practice Sheet #13

Lists, Stacks and Queues in C. CHAN Hou Pong, Ken CSCI2100A Data Structures Tutorial 4

CSCI 171 Chapter Outlines

Structures. Basics of Structures (6.1) EECS l Now struct point is a valid type. l Defining struct variables: struct point { int x; int y; };

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

Memory Management. a C view. Dr Alun Moon KF5010. Computer Science. Dr Alun Moon (Computer Science) Memory Management KF / 24

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

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

CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-1-0)

C programming basics T3-1 -

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


Scheme of valuations-test 3 PART 1

Abstract Data Types. Abstract Data Types

Transcription:

ENEE150 Final Exam Review Topics: Pointers -- pointer definitions & initialization -- call-by-reference and Call-by-value -- pointer with arrays -- NULL pointer, void pointer, and pointer to pointer Strings -- string defined with pointer -- string manipulation functions: string searching, string comparison, string copy, string concatenation, string tokenizing Dynamic memory allocation (malloc, free, calloc, realloc) Structure -- structure template and variable declaration -- typedef -- Access members (using dot or arrow) -- nested structures Linked List -- understand pointer to pointer sptr -- understand how to insert/delete a node, and display the list. -- stack: push and pop (LIFO) -- queue: enqueue and dequeue (FIFO) ADT -- definition of ADT, advantage of using ADT -- be able to give the abstract view of an ADT given specifications (.h file) -- understand concept of constructor and deconstructor Review Problems: (Please review all the practice problems in the midterm review sheet) 1. What is displayed by the following program segment if all variables are of type int and the input data is the data shown? st = scanf("%d%d%d", &n, &m, &p); printf("n=%d m=%d st=%d\n", n, m, st); Input data: 10 12 hello 2. What will be the output of the program? #include<stdio.h> 1

int x=30, *y, *z; y=&x; /* Assume address of x is 500 and integer is 4 bytes */ z=y; *y++ = *z++; x++; printf("x=%d, y=%d, z=%d\n", x, y, z); 3. Given the following declarations typedef struct char name[20]; int id; double salary; emprec_t;... emprec_t emp1, emp2; char ch1; int flag1, flag2; (1) Which of the following could not be a valid statement? a. emprec_t.id = 87654; b. emp1.salary *= 1.05; c. ch1 = emp2.name[0]; d. printf("%.2f", emp1.salary); e. All of the above are valid. (2) Which of the following could not be a valid use of the variables shown? You may assume that print_employee is a user-defined function. a. emp2 = emp1; b. flag1 = emp1 == emp2; c. flag2 = emp1.id == emp2.id; d. print_employee(emp1); e. All of the above are valid. 4. Given: typedef struct node_s double data; struct node_s *leftp, *rightp; node_t; 2

The name node_t is equivalent to. a. node_s * b. node_s c. struct node_s * d. struct node_s 5. Define a type named node_t that is appropriate for one node of a linked list in which each node's data consists of an integer and a 6-element array of type double. 6. If a linked list contains three nodes with values "him", "her", and "its", and start is a pointer to the list head, assume the following data structure, typedef struct node char pronoun[20]; struct node *next; Node; Node *np, *mp; What is the effect of each of the following statements? Describe how many nodes in the list and what the values of each node are. Each case is independent of each other. (1) np = start -> next; strcpy(np -> pronoun, "she"); (2) mp = start -> next; np = mp -> next; mp -> next = np -> next; free (np); (3) np = start; start = (Node *) malloc (sizeof (Node)); strcpy( start -> pronoun, "his"); start -> next = np; 7. Write a function that merges two linked lists. Assume the following data structure for the list: typedef struct node int num; struct node *next; NODE; 8. Give the output for the program below: #include <stdio.h> #include <stdlib.h> #define MAX 3 void init(int a[]) a[0] = 23; 3

a[1] = 56; a[2] = 17; void increase(int *p) p++; printf("%d\n", p[0]); int numbers[max], *other; init(numbers); other = (int*) malloc(max*sizeof(int)); init(other); increase(numbers); printf("%d\n", numbers[0]); other++; printf("%d\n", other[0]); 9. Write a function prototype for a function sum_n_avg that has three type double input parameters and two output parameters. n1 n2 n3 sum_n_avg sump avgp 10. Given the definition typedef struct stack_node_s char element; struct stack_node_s *next; stack_node_t; Draw the stack resulting from execution of the following code segments step by step. Assume you are working with a linked list implementation of a stack of individual characters. stack_node_t *sptr = NULL; push(&sptr, a ); push(&sptr, b ); pop(&sptr); push(&sptr, c ); 4

11. Given the definition in 10, write a push function to insert a character to the top of the stack (i.e. to the beginning of the linked list) void push (stack_node_t **sp, char c); 12. What will be the output of the following program if the starting address of x is 100, and the starting address of array a is 200? #include <stdio.h> int *p, x; int a[5]=100,200,300,400,500; int *p2; p=null; x=500; p=&x; printf("1) %d %d %u %u\n",x,*p,p,&x); p2=a; *(p2+1)=*p; *p= *p2 + *(p2+2); p2++; printf("2) %d %d %d %u\n",x,*p,*p2,p2); 13. What will be the output of the following program? #include<stdio.h> char *a[4]= "MC", "C Programming", "Data", "Structure"; char *p; int i; for (i=0;i <4;i++) printf("%s \n", a[i]); p = a[0]; printf("%c \n", *p); p=p+1; printf("%c \n", *p); p=&a[2][0]; printf("%c \n", *p); p=p+1; printf("%c \n", *p); 5

14. What will be the output of the following program? #include<stdio.h> struct course int courseno; char coursename[25]; ; struct course c[] = 102, "Java", 103, "PHP", 104, "DotNet" ; printf("%d ", c[1].courseno); printf("%s\n",(c+2)->coursename); 6

Review Problem Solution 1. n=10 m=12 st=2 2. x=31, y=504, z=504 3.1) a 2) b 4. d 5. typedef struct node_s int num; double list[6]; struct node_s *restp; node_t; 6 (1) It replaces "her" by "she". So we still have three nodes with values "him", "she", and "its". (2) The third node in the list is deleted. We only have two nodes with values "him" and "her". (3) A new node with value "his" is inserted in the beginning of the list. We will have four nodes with values "his", "him", "her", and "its". 7 void merge(node **first, NODE **second) NODE *end,*start; /* Find the current pointer to two lists */ end = *first; start = *second; /* Find tail of the first list */ while ( end -> next!= NULL ) end = end ->next; /* Tail of the first list points to the head of the second list */ end -> next = start; 8. Output of the program is: 56 23 56 9. void sum_n_avg (double n1, double n2, double n3, double *sump, double *avgp); 7

10. b c a a a a 11. void push (stack_node_t **sp, char c) stack_node_t *newptr; newptr =(stack_node_t *) malloc(sizeof(stack_node_t)); newptr -> element = c; newptr -> next = *sp; *sp = newptr; 12. 1) 500 500 100 100 2) 400 400 500 204 13. MC C Programming Data Structure M C D a 14. 103 DotNet 8