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

Similar documents
CSCI 2132 Final Exam Solutions

CS 0449 Sample Midterm

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14

Bit Manipulation in C

CGS 3460 Summer 07 Midterm Exam

Agenda. The main body and cout. Fundamental data types. Declarations and definitions. Control structures

C Program Development and Debugging under Unix SEEM 3460

Introduction to C An overview of the programming language C, syntax, data types and input/output

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

C-Programming. CSC209: Software Tools and Systems Programming. Paul Vrbik. University of Toronto Mississauga

CS 261 Fall C Introduction. Variables, Memory Model, Pointers, and Debugging. Mike Lam, Professor

Programming in C - Part 2

MIDTERM EXAM. CS 217 October 28, Name: Precept: Honor Code: Score: Problem Score Max

ET156 Introduction to C Programming

C Programming Review CSC 4320/6320

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

Motivation was to facilitate development of systems software, especially OS development.

THE UNIVERSITY OF WESTERN ONTARIO. COMPUTER SCIENCE 211a FINAL EXAMINATION 17 DECEMBER HOURS

CSCI 2132 Software Development. Lecture 20: Program Organization

C Introduction. Comparison w/ Java, Memory Model, and Pointers

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

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

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 14

Control Flow, Functions and Basic Linkage

The make Utility in Unix SEEM

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

Lab Session # 1 Introduction to C Language. ALQUDS University Department of Computer Engineering

The make Utility in Unix SEEM

Programming in C Quick Start! Biostatistics 615 Lecture 4

Week 3 Lecture 2. Types Constants and Variables

C Language Part 2 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

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

Kurt Schmidt. October 30, 2018

C: How to Program. Week /Mar/05

Topic 6: A Quick Intro To C

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

Procedures, Parameters, Values and Variables. Steven R. Bagley

Introduction to C. Sami Ilvonen Petri Nikunen. Oct 6 8, CSC IT Center for Science Ltd, Espoo. int **b1, **b2;

Deep C. Multifile projects Getting it running Data types Typecasting Memory management Pointers. CS-343 Operating Systems

Motivation was to facilitate development of systems software, especially OS development.

Memory Allocation in C

Subject: Fundamental of Computer Programming 2068

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

Procedural programming with C

AN OVERVIEW OF C, PART 3. CSE 130: Introduction to Programming in C Stony Brook University

PRINCIPLES OF OPERATING SYSTEMS

High Performance Computing

are all acceptable. With the right compiler flags, Java/C++ style comments are also acceptable.

M1-R4: Programing and Problem Solving using C (JAN 2019)

COMP s1 Lecture 1

Fundamentals of Programming Session 12

Introduction to Supercomputing

Lecture 3. More About C

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

The C Programming Language Guide for the Robot Course work Module

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

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

PROGRAMMAZIONE I A.A. 2017/2018

C for C++ Programmers

ALGORITHM 2-1 Solution for Exercise 4

Computer Systems Assignment 2: Fork and Threads Package

The C language. Introductory course #1

Presented By : Gaurav Juneja

This is CS50. Harvard University Fall Quiz 0 Answer Key

Fundamentals of Programming

Chapter 3. Section 3.10 Type of Expressions and Automatic Conversion. CS 50 Hathairat Rattanasook

JTSK Programming in C II C-Lab II. Lecture 3 & 4

ARRAYS(II Unit Part II)

ESC101N: Fundamentals of Computing End-sem st semester

COMP 2001/2401 Test #1 [out of 80 marks]

Lecture 2: C Programming Basic

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

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

Computer Science & Information Technology (CS) Rank under AIR 100. Examination Oriented Theory, Practice Set Key concepts, Analysis & Summary

Chapter 8: Intraprogram Communication. Lecture 8 1

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

Linux Systems Administration Shell Scripting Basics. Mike Jager Network Startup Resource Center

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

Variation of Pointers

Functions in C C Programming and Software Tools

CMPT 115. C tutorial for students who took 111 in Java. University of Saskatchewan. Mark G. Eramian, Ian McQuillan CMPT 115 1/32

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

ET156 Introduction to C Programming

Programming in C. Pointers and Arrays

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

int marks[10]; // fixed size and fixed address No change in Memory address.

CSE 2421: Systems I Low-Level Programming and Computer Organization. Functions. Presentation C. Predefined Functions

What we have learned so far

SAMPLE MIDTERM SOLUTION


Fundamental of Programming (C)

Functions. Chapter 5

C++ C and C++ C++ fundamental types. C++ enumeration. To quote Bjarne Stroustrup: 5. Overloading Namespaces Classes

CMPE-013/L. Introduction to C Programming

Compiling and Running a C Program in Unix

Lecture 10: Potpourri: Enum / struct / union Advanced Unix #include function pointers

C PROGRAMMING Lecture 4. 1st semester

{C} Programming. Part 1/2 Basics Variables, Conditions, Loops, Arrays, Pointer basics

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

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

Transcription:

1. Short answer questions: (a) Compare the typical contents of a module s header file to the contents of a module s implementation file. Which of these files defines the interface between a module and a program? (50 words or less) (b) What is a pointer and how is it related to an array? (25 words or less) (c) What is a string? (25 words or less) 2.What does the following program print? #include <stdio.h> int main() { char s[] = Hsjodi, *p; for (p = s + 5; p >= s; p--) --*p; puts(s); return 0;

3.(a) Describe the behaviour of the following program: #include <stdio.h> #include <stdlib.h> #define FOREVER 1 #define STOP 17 void f(); int main(){ while (FOREVER) f(); return 0; void f(){ static int cnt = 0; printf( cnt = %d\n, ++cnt); if (cnt == STOP) exit(0); (b) How does static modify the scope and lifetime of cnt in function f?

4. Explain how the static keyword modifies the storage class and linkage of the variables i and j in the following program fragment: #include <stdio.h> static int i; void foo(int i) { static int j; printf( %d\n, i + j++); 5. Write a function that orders the stored values of three characters. Suppose, for example, that c1, c2, and c3 are character variables having the values C, B, and D, respectively. Then the function call order_chars(&c1, &c2, &c3) should cause the stored values of c1, c2, and c3 to be B, C, and D, respectively.

6. (a) Write a complete C program called reverse.c that echoes its command-line arguments in reverse order. Running the program by typing reverse void and null should produce the following output: null and void (b) Write a one-line UNIX command to: compile the program in (a) and produce an executable file called reverse run reverse with arguments holidays the for home and send the output to a file called greeting run reverse with arguments holidays the for home and send the output to the lpr command (which prints the contents of its input)

7.(a) Consider the following series of Linux commands: $ cat test This file has two lines $ wc -w test 5 test $ mkdir tempdir $ mv test tempdir $ ls tempdir wc -w What is the output of the last command?

8. The following function is supposed to return TRUE if any element of the array a has the value 0 and FALSE if all elements are nonzero. Sadly, it contains an error. Find the error and show how to fix it: #define TRUE 1 #define FALSE 0 typedef int Bool; Bool has_zero(int a[], int n) { int i; for(i = 0; i < n; i++) if(a[i] == 0) return TRUE; else return FALSE;

9. Consider the following program: #include <stdio.h> float avg(float, float); int main(){ int x, y; printf("enter two numbers: "); if(scanf("%d %d", &x, &y)!= 2){ printf("error reading input!\n"); return 1; printf("the average of %d and %d is: %f\n", x, y, avg(x,y)); return 0; float avg(float i, float j) { return (i + j)/2; What output is produced if the input is the two integers 3 and 4? What would happen if the function declaration (second line: float avg(float, float);) was removed?

10. Which one of the following file types never need to be placed under source control, and why? (a) C source code (b) Object file produced by a compiler (c) C header file (d) Executable file produced by a compiler (e) Text file containing documentation for a program 11. Suppose a program consists of three source files, main.c, llist.c, btree.c, and header files llist.h and btree.h. llist.c and btree.c are linked list and binary tree modules, respectively, which are both called by main.c. (a) Which header files should be included in each of main.c, llist.c, btree.c? Explain why in each case. (b) Write a UNIX makefile for this program, assuming that the executable file is called demo.

12. Let f be the following function: int f(char *s, char *t){ for (; *s == *t; s++, t++) if (*s == \0 ) return 0; return *s - *t; (a) What is the value of f( apples, oranges )? (b) What is the value of f( hello, hello )? (c) In general, what value does f return when passed two strings s and t?

13. Consider the following structure data type for a node in a linked list: typedef struct node{ int value; struct node *next; nodet; (a)fix the two errors in the following function, which inserts a node at the front of a linked list: nodet *insertfront(nodet *list, int d) { nodet *aux; aux->value = d; aux->next = list; return; (b) Implement the following function that counts the nodes in a linked list: unsigned int count_list(nodet *list);