Approximately a Test II CPSC 206

Similar documents
Approximately a Final Exam CPSC 206

Fundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University

Chapter 8 - Characters and Strings

Muntaser Abulafi Yacoub Sabatin Omar Qaraeen. C Data Types

C mini reference. 5 Binary numbers 12

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

THE FUNDAMENTAL DATA TYPES

Array Initialization

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

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

today cs3157-fall2002-sklar-lect05 1

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath

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

Announcements. Strings and Pointers. Strings. Initializing Strings. Character I/O. Lab 4. Quiz. July 18, Special character arrays

Fundamentals of Programming Session 4

Strings and Library Functions

Arrays and Pointers in C. Alan L. Cox

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

Converting a Lowercase Letter Character to Uppercase (Or Vice Versa)

Chapter 8: Character & String. In this chapter, you ll learn about;

Fundamentals of Programming. Lecture 11: C Characters and Strings

C: How to Program. Week /May/28

A Fast Review of C Essentials Part I

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

LESSON 4. The DATA TYPE char

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

SOFTWARE Ph.D. Qualifying Exam Fall 2017

Characters and Strings

CS201- Introduction to Programming Latest Solved Mcqs from Midterm Papers May 07,2011. MIDTERM EXAMINATION Spring 2010

C: How to Program. Week /Mar/05

UNIT-I Input/ Output functions and other library functions

Laboratory 2: Programming Basics and Variables. Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information

The detail of sea.c [1] #include <stdio.h> The preprocessor inserts the header file stdio.h at the point.

8. Characters, Strings and Files

Fundamental of Programming (C)

Chapter 8 C Characters and Strings

Chapter 2 - Introduction to C Programming

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

Arrays, Strings, & Pointers

LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are:

BLM2031 Structured Programming. Zeyneb KURT

C Libraries. Bart Childs Complementary to the text(s)

Fundamental of Programming (C)

Programming Fundamentals (CS 302 ) Dr. Ihsan Ullah. Lecturer Department of Computer Science & IT University of Balochistan

Arrays and Pointers (part 1)

Fundamentals of Programming. Lecture 3: Introduction to C Programming

CS3157: Advanced Programming. Outline

ANSI C Programming Simple Programs

Signature: ECE 551 Midterm Exam

Programming for Engineers Arrays

Compiling and Running a C Program in Unix

cs3157: another C lecture (mon-21-feb-2005) C pre-processor (3).

Writing an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and

Arrays and Pointers. CSE 2031 Fall November 11, 2013

Multiple Choice Questions ( 1 mark)

return return else return

PRINCIPLES OF OPERATING SYSTEMS

First of all, it is a variable, just like other variables you studied

Tokens, Expressions and Control Structures

Makefiles Makefiles should begin with a comment section of the following form and with the following information filled in:

Variables and Constants

Basic Elements of C. Staff Incharge: S.Sasirekha

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

Computers Programming Course 5. Iulian Năstac

C OVERVIEW. C Overview. Goals speed portability allow access to features of the architecture speed

Armide Documentation. Release Kyle Mayes

ET156 Introduction to C Programming

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

In this session we will cover the following sub-topics: 1.Identifiers 2.Variables 3.Keywords 4.Statements 5.Comments 6.Whitespaces 7.Syntax 8.

else return for return

CSCI 2132 Final Exam Solutions

CSE 1001 Fundamentals of Software Development 1. Identifiers, Variables, and Data Types Dr. H. Crawford Fall 2018

Fundamentals of C. Structure of a C Program

File IO and command line input CSE 2451

Basic Types and Formatted I/O

Presented By : Gaurav Juneja

Midterm Exam Nov 8th, COMS W3157 Advanced Programming Columbia University Fall Instructor: Jae Woo Lee.

Chapter 7. Pointers. Copyright 2007 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved.

Understanding Pointers

AIR FORCE SCHOOL,BAMRAULI COMPUTER SCIENCE (083) CLASS XI Split up Syllabus (Session ) Contents

Lecture 04 Introduction to pointers

Characters, c-strings, and the string Class. CS 1: Problem Solving & Program Design Using C++

Fundamentals of Programming

C OVERVIEW BASIC C PROGRAM STRUCTURE. C Overview. Basic C Program Structure

Arrays and Pointers (part 1)

BASIC ELEMENTS OF A COMPUTER PROGRAM

CSCI 171 Chapter Outlines

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

mith College Computer Science CSC270 Spring 2016 Circuits and Systems Lecture Notes, Week 11 Dominique Thiébaut

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

Data Types and Variables in C language

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

ECE 264 Exam 2. 6:30-7:30PM, March 9, You must sign here. Otherwise you will receive a 1-point penalty.

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

Work relative to other classes

C Programming. Unit 9. Manipulating Strings File Processing.

A function is a named group of statements developed to solve a sub-problem and returns a value to other functions when it is called.

Computer Programming

SWEN-250 Personal SE. Introduction to C

CSCE150A. Introduction. Basics. String Library. Substrings. Line Scanning. Sorting. Command Line Arguments. Misc CSCE150A. Introduction.

Transcription:

Approximately a Test II CPSC 206 Sometime in history based on Kelly and Pohl Last name, First Name Last 5 digits of ID Write your section number(s): All parts of this exam are required unless plainly and explicitly announced by the instructor during class. Each True/False problem is to be answered T for true or F by circling the appropriate letter. For multiple choice and questions the answer is to be entered by circling the label. The worth of individual problems is shown like [9]. If you have a question about a problem, write the question, the answer you are assuming, and continue. In other words, do not ask it aloud!! Verbosity is discouraged. We have provided sufficient lined space for answers. In some cases we may have provided more than enough. Written answers should be written in good English. Neatness counts and we reserve the right to assign lower grades for sloppiness, much lower! Do not remove the staple or tear exam packet apart! Calculators, PDAs, CD players, radios, and headphones are not allowed! K, M, G may be used. If so, K = 2 10 = 1024, M = 2 20 = 1024 2, G = 2 30 = 1024 3. Aggies do not lie, cheat, or steal and do not tolerate those who do! I have obeyed the Aggie code of honor in my answers on this exam. Signature Page 1 2 3 4 5 6 7 Total Max Pts 3 15 15 20 24 23 20 120 Your Points

True/False. 1. [1] T F The presence of a semicolon after the closing right parenthesis of a function header indicates that this header is a prototype. 2. [1] T F The code fragment char *p="howdy boys\n" "and girls\n"; printf("%s", p); will compile cleanly and run without error. 3. [1] T F A return NULL; statement should appear just before the closing brace for a function of type void. 4. [1] T F A potential line of C source contains the assignment short_string = "Howdy!"; Assume the declaration char *short_string preceeded the assignment. The effect of the assignment statement is to assign the address of the string constant to the pointer short_string. 5. [1] T F A potential line of C source contains *shorter_string = A ; Assume that shorter_string has been declared by char *shorter_string; and initialized to a non-trivial string. The effect of the assignment statement is to assign the address of the character constant to the pointer shorter_string. 6. [1] T F A declaration int *ii = NULL, jj; followed by jj = *ii; sets the value of jj to zero. 7. [1] T F A variable named bool of type int was created for logic purposes and given a value. The result of bool ==!(! bool) is always true. 8. [1] T F Call-by-value means that the value of an argument is passed to and returned from the called function. 9. [1] T F This type definition is valid in C: typedef enum {A= A, B, c} Letters; 10. [1] T F The exit(return_value); statement is quite similar to the return return_value; except that it can be used in functions and returns control all the way to the operating system. 11. [1] T F Enumerators (the enumerator constants) can be explicitly initialized. 12. [1] T F A programmer can use the typedef statement to create another name for a fundamental data type. 13. [1] T F The name of an array when used without subscripts can be used in all places that a pointer can be used. 14. [1] T F These initializations are legal in C: int *p = &i, i = 65535; 15. [1] T F The statement printf("%c", \t ); will output a tab character to the screen. 2

16. [1] T F The constants "z" and z are not the same. 17. [1] T F The function isalnum returns true if the argument is an alphabetic character, numeric digit, or an underscore. 18. [1] T F These numbers are all the same in C: 7, 07, and 0x07. 19. [1] T F The expected output of printf("%d",sizeof( z )); is the digit 1. 20. [1] T F The unary operator sizeof(arg) returns the number of bytes needed to store the arg if it is a constant or the number of bytes allocated for arg if it is a variable. 21. [1] T F In C it is guaranteed that sizeof(short) <= sizeof(int) <= sizeof(long) 22. [1] T F In C it is guaranteed that sizeof(signed) == sizeof(int) == sizeof(unsigned) 23. [1] T F In C, sizeof(char *) == sizeof(char) 24. [1] T F Any variable regardless of type always uses 4 bytes of memory. 25. [1] T F The function putchar has no arguments and returns an int. 26. [1] T F Local (auto) variables are not automatically initialized by the system to 0. 27. [1] T F If ptr is declared int *ptr; then &*ptr is equivalent to ptr. 28. [1] T F Local (auto) variables can be used only in a block or function body in which they are declared. The problems on the rest of this page should be answered in the context of C, unix, and similar programming environments as reflected in the class, notes, and laboratories. 29. [1] T F This command on a unix command line my_program > junk.txt causes the input of my_program to be taken from the file junk.txt. 30. [1] T F The value of the parameter argc as defined in main(int argc, char *argv[]) is the number of arguments after the name of the executable. 3

31. [2] What is the error in this code? Multiple Choice. #include <stdio.h> int main(void){ char Alpha[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ"; char alpha[27]="abcdefghijklmnopqrstuvwxyz"; alpha = Alpha; printf("alpha is now %s\n", alpha); return 0; } a. Array incorrectly initialized b. illegal assignment c. Variable names spelled the same d. printf does not need a pointer 32. [2] Which of the following is a valid preprocessor directive which will insert a header file containing prototypes for standard character type macros and functions? a. #include "stdlib.h" b. #include <stdio.h> c. #include <stdlib.h> d. #include <ctype.h> e. #insert "standard char prototype file" 33. [2] In general, when a double and long variables are combined in a single expression then a. the value of type double is converted automatically to type long before the expression is evaluated b. both values are converted automatically to long double to increase precision c. the expression is evaluated without any conversion d. the value of type long is converted automatically to type double before the expression is evaluated e. there is a syntax error, because double and long variables cannot be combined in one expression 34. [2] What is the value of count after execution of the for loop? int sum = 0, count; for (count=0; count <=4; count++) sum+=count; a. 0 b. 3 c. 4 d. 5 e. the value of count is not defined after the for loop 35. [2] A user-defined function can be placed (assuming that the function s prototype is located correctly): a. before the main() function b. after the main() function c. in another file d. all of the above is true 4

36. [2] Why does the following piece of code give a compile time error? const int integer = 20000; integer++; a. integer is not a proper variable name b. the value 20000 is too big for a variable of type int c. it increments a variable declared as const d. const cannot be used in that context 37. [2] Given the following declaration: int a[1500]; which of the following is not a valid C expression? a. a - 1 b. a + 1500 c. a++ d. a[150] 38. [2] Given the following array declaration and initialization: int a[5] = {0, 1, 2}; what is the value of a[4]? a. 0 b. 1 c. 2 d. a[4] is not initialized. 39. [2] Which one is correct? In C, a string a. is an array of characters, terminated by a b. is a fundamental data type \0 c. cannot be initialized d. is another name for type char 40. [2] Given the following declaration: int a[10]; which of the following gives the address of the third element of a? a. a[3] b. a + 1 c. *(a + 2) d. a + 3 41. [2] What does the function test do? void test(char *s1, const char *s2) { int i; for (i = 0; i < strlen(s2); i++) s1[i] = s2[i]; s1[i] = \0 ; } a. It concatenates the strings s1 and s2, and the result is stored in s1. b. It compares the strings s1 and s2. c. It computes the length (size) of the string s1. d. It copies elements of the string s2 to the string s1. 5

42. [2] When an array is passed as a parameter to a function, what is actually passed? a. A copy of all elements of the array b. pointer to the first element of the array c. The first element of the array d. A pointer to the end of the array 43. [2] What is the value of j after the following code is run int i, j = 0; int a[] = {0, 1, 2, 3, 4, 5, 6, 7}; for (i = 0; i <= 7; i++) j += (a[i] <= 3); a. 0 b. 2 c. 4 d. 6 Problems Remember the verbosity instructions. 44. [5] Why is this construct considered to be dangerous typedef enum {true, false} Bool;? 45. [5] The use of the scanf() function normally requires that we use the address operator (&). Why is this not required when we input a string with a statement scanf("%s", string_name); 46. [5] What does the function test2 do? unsigned test2( const char *S ) { unsigned int i = 0; while( S[i]!= \0 ) i++; return i; } 6

47. [20] Assume that you have an email message with uppercase and lowercase letters. For example, some sentences begin with lowercase letters and the rest of the sentence may be all UPPERCASE. You will complete the program below by replacing all letters in a line with lowercase letters but each sentence must start with an uppercase letter. Complete the program mail_correction.c which will make the indicated corrections to such messages. Test data will be in the file message.in. What command line instruction will you issue to: Compile the program: Execute the program with data: These assumptions are to be made about each email message a. There will not be any leading spaces on a line. b. Each sentence in the data files will be on one line. c. There may be more than one sentence on a line. d. The period is the only sentence ending mark used. e. There will be only one space after the sentence ending period. f. Thus, later sentences on a line follow a period and space. This is the program you need to complete. #include <stdio.h> #include <string.h> int main(void){ int i=0, j=0, k=0, n; /* if needed */ char a_line[132]; while( gets( a_line )!= NULL ) { /* Your lines of code go here */ printf("%s\n", a_line); } return 0; } You should use the functions toupper and tolower. You may use isalpha. These take a character as an argument and return a character. Assume the function gets(char a[]); reads one line of characters into the array a until a newline or end-of-file is encountered. A \0 is appended after the last read character in the array. It returns the address of a if successful, NULL otherwise. What assumptions about the functions toupper and tolower are made? 7