final study

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

T/F - You must explicitly use fopen to open the standard input, standard output, and error stream

False - standard input, standard output, standard error automatically are opened by C when program execution begins

What is the outcome/output of the following C program, if any? #include<stdio.h> void main() { int a =4,b=16; b >> 3; a = a << b; printf("%d %d ", b, a ); }

16, 262114 (b >> 3 should be b = b >> 3)

What is the outcome/output of the following C program, if any? #include<stdio.h> void main(void){ int check=2; switch(check){ case 1: printf("1\n"); case 2: printf("2\n"); case 3: printf("3\n"); default: printf("what ever\n"); } }

2 3 whatever

What will be output when you execute following c code? #include<stdio.h> void main(void){ char data[3][2]={0,1,2,3,4,5}; printf("%d ",data[1][0]); }

2 (draw 2D array to see elements)

What is the outcome/output of the following C program, if any? #include <stdio.h> int main(void) { int x = 2, y = 2; x /= x / y; printf("%d\n", x); return 0; }

2 (it is x/x/y)

How many A's will be printed and how many B's will be printed with the following code snippet? i=0; while (i<5){ printf("A "); i+=3; } while (i<7){ printf("B "); i+=2; } 6 A's and 6 B's 2 A's and 4B's 4 A's and 6 B's 4 A's and 4 B's 2 A's and 1 B's

2 A's and 1 B's

What is the outcome/output of the following C program, if any? #include<stdio.h> void main() { union var { int a; int b; }; union var v; v.a=10; v.b=20; printf("%d\n", v.a); }

20 members share the same memory if v.a and v.b statements were switched, output would be 10

T/F - Function fscanf cannot be used to read std input

False - you can use fscanf to read from standard input, you just have to specify the pointer to standard in when calling fscanf

Which operator has the highest precedence? a) * (unary) b) * (multiplicative) c) == (equality) d) *= (assignment) b d c a

a

Which statement is true? a) The address operator (&) is an unary operator and the indirection operator (*) is an unary operator. b) The address operator (&) is NOT an unary operator and the indirection operator (*) is an unary operator. c) The address operator (&) is an unary operator and the indirection operator (*) is NOT an unary operator. d) The address operator (&) is NOT an unary operator and the indirection operator (*) is NOT an unary operator. a d b c

a

Which variable from the code snippet below is responsible for shifting the value (i.e,. the first number in the desired range of the consecutive integers) of the random number being generated? int a,b,n; n = a + rand() % b; a b c

a

Fix the errors and analyze the output for each #include<stdio.h> void main(void){ int a=0,b=10; if(a=7) printf(" a is 7"); else printf("a is not 7"); if(10==b) printf(" b is 10 "); else printf("b is not 10"); if(a=0) printf(" a is 0"); else printf("a is not 0"); if(7=a) printf(" a is 7"); else printf("a is not 7"); }

a = 7 should be a == 7, a = 0 should be a == 0, 7 = a should be 7 == a

What is the outcome/output of the following C program, if any? #include<stdio.h> /* note the use of ; at the end of if statement */ void main(void){ int a=0,b=0,c=10; if(a); printf("a is %d\n",a); if(b) printf("b is %d\n",b); }

a is 0 (no idea why. Prints nothing when the semicolon is taken away)

What is being printed by the following snippet of code? int a = 4; if (a = 5) printf("a is 5"); else printf("a is 4");

a is 5

each file must have

a pointer of type FILE that's used to refer to the file

function rewind causes

a program's file position pointer to be repositioned to the beginning of the file pointed to its argument

c views each file simply as

a sequential stream of bytes

when a file is opened

a stream is associated with it - three streams automatically opened

Which of the following is an invalid assignment operator? A. a %= 10; B. a /= 10; C. a |= 10; D. None of the mentioned

a |= 10;

Which of the following assignments is/are invalid? a) myArray[2] = 10; b) myArray[12 +1 3] = 5; c) myArray[16 / 4] = 105; d) myArray[4.0 / 2.0] = 120; f) myArray[10 % 2] = 15;

d

Point out the error in the program? #include<stdio.h> void main() { FILE *fp; fp=fopen("trial", "r"); fseek(fp, "20L", SEEK_SET); fclose(fp); }

" " around 20L

Which header file should be included to use the pow() function? #include <limits.h> #include <stdlib.h> #include <stdio.h> #include <math.h>

#include <math.h>

Which header file should be included to use the pow() function? #include <math.h> #include <limits.h> #include <stdlib.h> #include <stdio.h>

#include <math.h>

Which include directive is needed to use the srand() function in a C program? #include <stdio.h> #include <stdlib.h> #include <time.h> #include <random.h>

#include <stdlib.h>

Which of the following are reserved keywords and can not be used for identifier names? count ifelse number long while

long, while

The bitwise AND operator (&) is often used to _______ bits that is to select certain bits while zeroing others.

mask

r

open a file for reading

ab+

open or create a file for update in binary mode; writing is done at the end of the file

fopen

opens a file

fscanf

reads data from a file in a manner similar to how scanf reads from standard input

If a linear search is performed against an array containing n items and is searching for the value of key that is contained in the array, what could be the smallest number of times the comparison array[j]==key would need to be performed, where j goes from 0 to (n-1) to find the value being searched for (best case scenario)? (n-1) times 1 0 n times

1

What is the outcome/output of the following C program, if any? #include<stdio.h> void main(){ int __BIG__ = 32; int y; y= __BIG__ && 8; printf("%d",y); }

1

What is the output of the following program? #include <stdio.h> int main(void) { int n = 1; { int n = 2; { auto int n = 3; printf("%d", n); } printf("%d", n); } printf("%d\n", n); } 321 123 111 333

321

What is the output of the following program? #include <stdio.h> int main(void) { int n = 1; { n = 2; { n = 3; printf("%d", n); } printf("%d", n); } printf("%d\n", n); } 123 333 321 111

333

Which logical unit of computer architecture typically performs calculations and comparisons?

Arithmetic and logic unit

A union cannot be nested in a structure A. True B. False

B can be nested

getc() returns EOF when .....

Both A and B

Which of the following errors would be reported by the compiler on compiling the program given below? #include<stdio.h> void main(void) { int a = 5; switch(a) { case 1: printf("First\n"); case 2: printf("Second\n"); case 3 + 2: printf("Third\n"); case 5: printf("Final\n"); break; } } A. There is no break statement in each case. B. Expression as in case 3 + 2 is not allowed. C. Duplicate case 'case 5': D. No error will be reported.

C

Which of the statements is correct about the program? #include<stdio.h> void main(void) { int i=10; int *j=&i; } A. j and i are pointers to an int B. i is a pointer to an int and stores address of j C. j is a pointer to an int and stores address of i D. j is a pointer to a pointer to an int and stores address of i

C

What is the outcome/output of the following C program, if any? int main(void) { int a = 10, b = 10; if (a = 5) b--; printf("a=%d, b=%d\n", a, b--); } A. a = 10, b = 9 B. a = 10, b = 8 C. a = 5, b = 9 D. a = 5, b = 8

C (a is assigned the value of 5 and b is decreased by 1)

Which of the following statements are correct about the below program? #include<stdio.h> void main(void) { int i =5, j = 20; if(i = 5) && if(j = 20) printf("Have a nice day"); } A. Output: Have a nice day B. No output C. Error: Expression syntax D. Error: Undeclared identifier if

C (should be if(i == 5) && if(j == 20))

What is the outcome/output of the following C program, if any? #include<stdio.h> void main(){ int ABC=10; printf("%d",abc); }

Compilation Error (capitalization matters)

What is the outcome/output of the following C program, if any? #include<stdio.h> void main(void){ switch(0X0){ case '\0':printf("\0"); break; case 0: printf("0"); break; default: printf("default"); } }

Compile Error ('\0' is NULL and runs as 0 so there are 2 case 0s)

Which bitwise operator is suitable for turning on a particular bit in a number? A. && operator B. & operator C. || operator D. | operator

D

Which bitwise operator is suitable for turning on a particular bit in a number? A. && operator B. & operator C. || operator D. | operator

D

Which of the following statements correctly assigns 12 to structure member month? #include<stdio.h> struct date { int day; int month; int year; }; void main() { struct date d, *pdt; pdt = &d; } I. pdt.month = 12 II. &pdt.month = 12 III. d.month = 12 IV. pdt->month = 12 A I & III B. III & IV C. I & III D. II & IV

D ptr = arrow notation var = dot notation

What is the outcome/output of the following C program, if any? #include<stdio.h> void main() { enum days {MON=-1, TUE, WED=6, THU, FRI, SAT}; printf("%d, %d, %d, %d, %d, %d\n", MON, TUE, WED, THU, FRI, SAT); } A. -1, 0, 1, 2, 3, 4 B. -1, 2, 6, 3, 4, 5 C. -1, 0, 6, 2, 3, 4 D. -1, 0, 6, 7, 8, 9

D starts at -1, increases by one, changed to 6, continues to increase by 1

Function fseek may seek a) relative to the beginning of a file. b) relative to the end of a file c) relative to the current location of a file d) all the above e) none of the above

D (can seek the beginning, end, and current location)

What is the outcome/output of the following C program, if any? #include<stdio.h> void main() { enum days {MON=-1, TUE, WED=6, THU, FRI, SAT}; printf("%d, %d, %d, %d, %d, %d\n", MON, TUE, WED, THU, FRI, SAT); } A. -1, 0, 1, 2, 3, 4 B. -1, 2, 6, 3, 4, 5 C. -1, 0, 6, 2, 3, 4 D. -1, 0, 6, 7, 8, 9

D (counts through until it is interrupted and then starts counting from that value)

What is the outcome of this code when compiled and executed? #include<stdio.h> void main() { int a=4;int b=8;if ( a & b) printf("True"); else printf("False"); }

False (a&b gives 0)

fseek() should be preferred over rewind() mainly because

In rewind, there is no way to check if the operations completed successfully

Point out the error, if any in the for loop. #include<stdio.h> void main(void) { int i=1; for(;;) { printf("%d\n", i++); if(i>10) break; } }

No error (output it 1 2 3 4 5 6 7 8 9 10)

What is the outcome/output of the following C program, if any? #include<stdio.h> void main(){ int big=100; int small=50; int diff-val = big - small; printf("%d",diff-val); }

No output (no - in variable names)

What is the outcome/output of the following C program, if any? #include<stdio.h> void main(void){ int x=-1,y=-1; if(++x = ++y) printf(" Equal "); else printf("Not equal"); }

Not Equal (++x = ++y is assignment not equivalent)

Is the following function prototype valid, that is to say, does it contains valid syntax? double foo(int a , int); True False

True

What is the scope of the variable x in the following program? #include <stdio.h> int cube(int n); int b = 10; int main(void) { int a = 10; printf("%d\n", cube(a)); } int cube(int x) { int y = x * x * x; return y; } function scope block scope file scope function-prototype scope

block scope

fclose

closes a file

standard error

displays error message on the screen

standard output

displays output on screen

fscanf is equivalent to scanf except

fscanf receives as an argument a pointer to a file

Is the following a legal or illegal identifier in C? "2ndvar"

illegal

Is the following a legal or illegal identifier in C? "test:"

illegal

file position pointer

indicates the number of the next byte in the file to be read or written

standard input

receives input from keyboard

random access file

records that you read from this type of a file are normally fixed in length, and may be accessed quickly because of this, this kind of file is good for transaction processing systems

A __________ function is a function that calls itself either directly or indirectly.

recursive

Structures can be compared by using operators == and != Why?

there can be gaps between the data

Which line number in the following program contains an error? 1. #include stdio 2. 3. // function main begins program execution 4. int main( void ) 5. { 6. printf( "Welcome to C!\n" ); 7. } // end function main

1

How many bits (binary digits) are there in one byte?

8

Which bitwise operator is suitable for turning off a particular bit in a number? A. && operator B. & operator C. || operator D. ! operator

B

All arguments in C are passed by value. True False

True

What is the outcome/output of the following C program, if any? #include<stdio.h> void main() { int a =4,b=16; b >> 3; a = a << b; printf("%d %d ", b, a ); }

16, 262114 should be b = b >> 3;

fgetc

reads a character from a specified file

Given the following code, what are some reasonable possibilities we could use to fill in the blank? int i = 10087;int *p = &i;int *q = _________; i q &i p

&i, p

False. The files will be closed when the program execution terminates, but all files should be explicitly closed with fclose.

(True or False) A program must explicitly call fclose to close a file.

False. In most cases, sequential file records are not of uniform length. Therefore, it's possible that updating a record will cause other data to be overwritten.

(True or False) Data in sequential-access files is always updated without overwriting other data.

False. Function fscanf can be used to read from the standard input by including the pointer to the standard input stream, stdin, in the call to fscanf.

(True or False) Function fscanf cannot be used to read data from the standard input.

False. It is possible to seek from the beginning of a file, from the end of a file and from the current location in the file.

(True or False) Function fseek may seek only relative to the beginning of a file.

False. Function rewind can be used to reposition the file position pointer to be the beginning of the file.

(True or False) If the file position pointer points to a location other than the beginning of the file, the file must be closed and reopened to read from the beginning of the file.

True.

(True or False) It's not necessary to search through all records in a random-access file to find a specific record.

False. Records in a random-access file are normally of uniform length.

(True or False) Records in a random-access files are not of uniform length.

What is the outcome/output of the following C program, if any? #include<stdio.h> void main(void){ int i=1; for(i=0;i=-1;i=1) { printf("%d ",i); if(i!=1) break; } }

-1

What is the outcome/output of the following C program, if any? #include<stdio.h> void main() { int x = 4 - 4 * 4 + 4; printf("%d\n", x); }

-8 (testing if you know pemdas)

What is the outcome/output of the following C program, if any? /* Note the ; at the end of for statement */ #include<stdio.h> void main(void){ int i; for(i=0;i>=5;i++); printf("%d",i); }

0 (since there is a ; at the end of the for loop, nothing is done in the loop)

What does the following program print? #include <stdio.h> int main( void ) { int count = 1; while ( count <= 5 ) { printf( "%s\n", count % 2 ? "0000" : "1111" ); (++count)+2; } return 0; }

0000 1111 0000 1111 0000

What is the first line of code that contains an error? 01) #include <stdio.h> 02) int myPower(int base, int exp) 03) 04) int main(void) 05) { 06) printf("%d raised to the %d power is %d\n", 2, 10, myPower(2,10)); 07) 08) return -1; 09) } 10) 11) int myPower (int base, int exp) 12) { 13) int answer = 1; 14) 15) for (int i = 1; i <= exp; i++) 16) answer = answer * base; 17) 18) return answer; 19) 20) }

02

What is the outcome/output of the following C program, if any? #include<stdio.h> void main(void) { int i=0; for(; i<=5; i++){ printf("%d", i); ++i; } }

024 (i is initialized at 0. It is then incremented to 1 and goes through the for loop and is 2. It is then incremented again and is 3 and is printed as 4)

What does the following program print? #include <stdio.h> int main( void ) { int count = 1; while ( count) {printf( "%d\n", count ); count=0; } return 0; } infinite loop 1 0 error 1

1

What is the output of the following program? #include <stdio.h> int main( void ) { int count1 = 1, count2 = 2; if ("0") { if (0) {printf( "%d\n", count1+1 );} else {printf("%d\n", count2-1 );} count1=0; } return 0; } error 1 0 3 2

1

What is the outcome/output of the following C program, if any? #include<stdio.h> #include<string.h> void main(void){ int a = 5,b = 10,c; int *p = &a,*q = &b; c = p - q; printf("%d\n" , c); c = *p - *q; printf("%d\n" , c); }

1 -5 (p has address of a and q has address of b declared variables a and b one after another c=p-q is why you get 1 *p is dereferencing if you are not DECLARING IT The first *p is a declaration Dereference just means getting the value that p points to)

What is the output of the following program? #include<stdio.h> main() { int i = 1; while(i){ printf("%d",i++); if(i==3) break; if(i<=5) continue; } } error 1 2 1 2 3 1 2 4 5

1 2

What is the output of this program #include <stdio.h> #include <stdlib.h> int funcA(int i) { int tmp=0; if (i>0) { tmp=(i + funcA(i-1)); printf("%d ",tmp); return tmp; } else return 0; } int main(void) { int x = funcA(8); printf("%d",x); }

1 3 6 10 15 21 28 36 36 (FuncA(i-1) keeps calling itself until I is 0)

Which of the following statements are correct about an array? 1: The array int num[5]; can store 5 elements. 2: The expression num[1] designates the very first element in the array. 3: It is necessary to initialize the array at the time of declaration. 4: The declaration num[SIZE] is allowed if SIZE is a macro.

1 and 4 (size of an array is stored in [ ]. SIZE is a macro means that the MACRO replaces the symbol SIZE with a given value)

What is the outcome/output of the following C program, if any? #include<stdio.h> void main(void) { char j=1; while(j < 5) { printf("%d, ", j); j = j+1; } printf("\n"); }

1, 2, 3, 4,

What is the outcome/output of the following C program, if any? #include<stdio.h> void main(void){ int x=8; do{ do{ printf("%o",x); } while(!-2); } while(0); }

10

What is the output of the following program? #include <stdio.h> int main( void ) { int count1 = 1, count2 = 2; if ("0") { {int count1 =count2+5; count1++; printf( "%d\n", count1+count2 );} } return 0; } error 8 11 10

10

What value of a in the snippet of code below generate a random number between 10 and 100? int a = ???; int b = 100; int c = a + rand() % (b - a + 1); 90 11 1 10

10

What is the outcome/output of the following C program, if any? #include<stdio.h> void main(void){ int i; for(i=10;i<=15;i++){ while(i){ do{ printf("%d\n",i); if( i >1) continue; }while(0); break; } } }

10 11 12 13 14 15 (program prints integers starting with 10 and then increasing by 1 until it reaches 15)

What is the output of this program #include<stdio.h> int givemesum() { static int num = 10; return num--; } int main(void) { printf("%d ", givemesum ()); printf("%d ", givemesum ()); return 0; }

10 9 (static means no change. without static, intnum = 10 gets deleted. return num-- returns num first and then decreases by 1)

If a bubble sort is performed on the following integer array: int myArray[] = {48, 29, 63, 11, 8, 10, 3}; What will be the value of a[2] after the first pass? 63 11 48 29

11

What is the output of the following program? 01. #include <stdio.h> 02. int main( void ) 03. { 04. int count = 10; 05. if (2>1) { 06. if (-1) {printf( "%d\n", count+1 );} 07. else {printf("%d\n", count-1 );} 08. count=0; 09. } 10. return 0; 11. } 10 error 11 9

11

What is the output of the following snippet of code? int arr[] = {1, 2, 3, 4, 7, 98, 0, 12, 35, 99, 14}; printf("%d", sizeof(arr)/sizeof(arr[0])); 11 0 1 10

11

What will be the output of the following snippet if n=1? switch ( n ) { case 1: printf( "1" ); case 2: printf( "2" ); break; default: printf( "3" ); break; 2 12 123 1

12

What is the outcome of this code when compiled and executed? #include<stdio.h> void main() { int a=4; int b=8; int c= a | b; printf("%d\n",c); }

12 bitwise operation

What is the outcome of this code when compiled and executed? #include<stdio.h> void main() { int a=4; int b=8; int c= a | b; printf("%d\n",c); }

12 (bitwise or adds)

#include<stdio.h> int addmult(int ii, int jj) { int kk, ll; kk = ii + jj; ll = ii * jj; return (kk, ll); } void main(void) { int i=3, j=4, k, l; k = addmult(i, j); l = addmult(i, j); printf("%d, %d\n", k, l); }

12, 12

What is the outcome/output of the following C program, if any? #include<stdio.h> void main(void){ int a=10, how_many_printed; how_many_printed = printf("123456789\n"); if(how_many_printed) printf("printf returned %d\n", how_many_printed); }

123456789 (printf returned 10)

What is the output of the following code? #include <stdio.h> int main(void) { int a=1, b=2, c=3; printf("%d%d\n%d\n", a,c,b); return0; }

13 2

What is the output of the following code? #include <stdio.h>i nt main(void) { int a=1, b=2, c=3; printf("%d%d%d\n", a,c,b); return0; }

132

What is the outcome/output of the following C program, if any? #include<stdio.h> void main() { union var { int a; int b; }; union var v; v.a=10; v.b=20; printf("%d\n", v.a); }

20 (can't have two things with the same datatype in union. 10 is overwrited in memory with 20)

What is the outcome/output of the following C program, if any? #include<stdio.h> void xyz=10; int main(){ int xyz=20; printf("%d",xyz); }

20 (two variables can have the same name and different scope)

What will be the output of the following snippet ? int counter=20; do { if ( counter % 2 == 0 ) { printf( "%d,", counter ); } counter += 2; } while ( counter > 100 ); 20, Infinite loop List of the integers from 2 to 100(exclusive) error List of the even numbers from 2 to 100 (exclusive)

20,

What does the following program do? #include "stdio.h" int main(void) { int i=20; do { if ( i % 2 == 1 ) break; i += 2; printf( "%d ", i ); } while ( i > 50 ); return 0; } 22 list of even numbers from 20 to 50 nothing error

22

What is the output of the following program? #include <stdio.h> int main( void ) { int count = 2; while ( count <= 3 ) { while ( count < 4 ) { printf("%d", count ); ++count; } } return 0; } 23 error 234 infinite loop

23

#include <stdio.h> int foo(int a); int bar(int b); int main(void) { int a = 3; a = foo(a); printf("The value of a is: %d\n", a); return 0; } int foo(int a) { a = a + 2; return bar(a); } int bar(int a) { return a * 5; } 5 1 8 3 25 15

25

What is the output for the following snippet of code? enum week{Mon, Tue, Wed, Thu, Fri, Sat, Sun}; int main(void) { enum week day; day = Thu; printf("%d\n", day); ... 4 Thu 3 thu

3

What is the output value of following code? void myFunc(int a); int main(void) { int a[] = {1,2,3,4,5,6,7,8,9,10}; myFunc( a[2] ); printf("The value of f(a[2]) is: %d\n", a[2] ); return 0; } void myFunc(int e) { e = e * 2; } The value of f(a[2]) is: 8 The value of f(a[2]) is: 4 The value of f(a[2]) is: 6 The value of f(a[2]) is: 2 The value of f(a[2]) is: 3

3

What value is printed by the following snippet of code? int a = 2, b = 4; int numberList[]={1,2,3,4,5,6,7,8}; printf("%d\n", numberList[a / b + 2]++); 2 None. Syntax error 4 1 3

3

What is the outcome/output of the following C program, if any? #include<stdio.h> void main(void){ int check=3; switch(check){ case 3: printf("3\n"); case 1: printf("1\n"); break; case 0: printf("0\n"); default: printf("what ever\n"); } }

3 1

What is the outcome/output of the following C program, if any? #include<stdio.h> void main(void){ int i = 3; int *j; int **k; j=&i; k=&j; printf("%u %u %d ",k,*k,**k); }

3 (value of k is whatever k is in the memory. value of *k means memory location that k keeps. **k is a double pointer. first one stores the address of the variable, second one stores the address of the first pointer.) (shortcut * and & always cancel each other out so *&a = a. *k = *(&aj) since k = &j. *(&j) becomes j which is garbage. **k = **(&j) = *(*&j) = *j = *(&i) = *&i = i = 3)

In which line the first error is appeared (if any)? 1. #include <stdio.h> 2. int main(void) { 3. printf("Welcome. Please enter your Zipcode.\n"); 4. zipcode=32766; 5. int zipcode; 6. if (zipcode > 32715 && zipcode < 3400) 7. printf(" Please Visit our website, next Monday."); 8. return 0; 9. }

4

What is the output of the following code? #include <stdio.h> int main( void ){ int i=2,j=3,x=1; if (i>0) { if(j>i){ x=j; x=j+1; printf("%d", x++); } else{ printf("%d",i); } } return 0; } nothing 4 2 3

4

What is the outcome/output of the following C program, if any? #include<stdio.h> void main(void){ int i=1,x=2; i=2+x*i++; printf("%d ",i); i *= x + i; printf("%d ",i); }

4 24 (follow pemdas)

What is the outcome/output of the following C program, if any? #include<stdio.h> int i; int fun1(int); int fun2(int); void main(void) { int i=3; fun1(i); printf("%d,", i); fun2(i); printf("%d ", i); } int fun1(int j) { printf("%d,", ++j); return 0; } int fun2(int i) { printf("%d,", ++i); return 0; }

4, 3, 4, 3

What is the outcome/output of the following C program, if any? #include<stdio.h> void main() { int a =4,b=2; b=b<< 1; a<< b; printf("%d %d ", b, a ); }

4, 4 should be a = a << b

What is the outcome/output of the following C program, if any? #include<stdio.h> void main() { int a =4,b=2; b=b<< 1; a<< b; printf("%d %d ", b, a ); }

4, 4 (a << b should be a = a << b)

What is the outcome/output of the following C program, if any? #include<stdio.h> void main(){ int xyz=20;{ int xyz=40; printf("%d\n",xyz); } printf("%d\n",xyz); }

4020 (variables outside brackets don't equal variables inside brackets)

What will be the output of the program if the array begins 4300 in memory? #include<stdio.h> void main(void) { int arr[]={2, 3, 4, 1, 6}; printf("%u, %u, %u\n", arr, &arr[0], &arr); }

4300, 4300, 4300 (arr and &arr point to the base address of arr. &arr[0] points to the address of the first element of arr so the base address)

How many times is the statement inside the for loop being run ? int timesRan = 0; while (timesRan<10) { timesRan+=2; } None. Invalid Syntax. 4 3 5

5

What is the value of a that is printed to the console by the following code? #include <stdio.h> void foo(int a); int main(void) { int a = 5; foo(a); printf("The value of a is: %d\n", a); return 0; } void foo(int a) { a = a + 2; return; } 2 5 0 7

5

What line below will generate a compile-time error? 1. #include <stdio.h> 2. 3. void func(const int num[]) 4. { 5. num[0] = 2; 6. } 7. 8. int main(void) 9. { 10. int num[] = {0 ,1 ,2}; 11. 12. func(num); 13. 14. printf("%d\n", num[0]); 15. return 0; 15. } 5 3 10 14

5

What is the outcome/output of the following C program, if any? #include<stdio.h> void main(void){ char data[2][3][2]={0,1,2,3,4,5,6,7,8,9,10,11}; printf("%d ",data[0][2][1]); }

5 (fills like this front: 0 2 4 1 3 5 back: 6 8 10 7 9 11)

What is the outcome/output of the following C program, if any? #include<stdio.h> void main(void){ int a=5; for(;;) { printf("%d ",a); if(!a--) break; } }

5 4 3 2 1 0 (code down increments until it reaches 0)

What is the output of the following code if the user enters 5 and 6 in order using a keyboard? #include <stdio.h> int main(void) { int a=1, b=2, c=3; scanf("%d%d",&a,&c); printf("%d%d\n%d\n", a,a+c,b+a); return0; }

511 7

What is output value of f(a[2]) in the following code? void myFunc(int a[], int s); int main(void) { int a[] = {1,2,3,4,5,6,7,8,9,10}; myFunc( a, 10 ); printf("The value of f(a[2]) is: %d\n", a[2] ); return 0; } void myFunc(int a[], int s) { a[2] *= 2; } 2 6 5 3 4

6

What is the first line of code that contains an error in the following? 1) #include <stdio.h> 2) int main() 3) { 4) int a = 10; 5) int *aPtr = &a; 6) aPtr = 20; 7) printf("The dereference of aPtr is: %d\n", *aPtr); 8) return 0; 9) } 8 5 6 4 7

6

What is the smallest value of b that can be used in the following array declaration? char[b] = "Hello";

6

What is the value of c after the following snippet: int c=3, product=2; while ( c <= 5 ) { ++c; product *= c;} 2 6 40 30

6

What is the outcome/output of the following C program, if any? #include<stdio.h> void main(void) { int i=0; for(; i<=5; i++); printf("%d", i); }

6 (because of the ; behind the for loop. If you remove the ; it will count to 5 and then exit)

What is the outcome/output of the following C program, if any? #include<stdio.h> void main(void){ int a=5,b=10; if(++a||++b) printf("%d %d",a,b); else printf("John Terry"); }

6 10 (since it is an or statement and the ++a comes back as true, it skips ++b)

Which line number(s) in the following program contain(s) an error? (Multiple answer) 1. #include <stdio.h> 2. 3. // function main begins program execution 4. int main( void ) 5. { 6. int x=2; y=3, z=x+y; 7. 8. Printf( "Welcome to C!\n" ); 9. }// end function main

6, 8

If a bubble sort is performed on the following integer array: int myArray[] = {48, 29, 63, 11, 8, 10, 3}; What will be the value of a[6] after the 3rd pass? 3 10 63 48

63

What is the outcome/output of the following C program, if any? #include<stdio.h> void main(void){ int a = 320; char *ptr; ptr =( char *)&a; printf("%d ",*ptr); }

64

What number is printed to the console when the following program is run? #include <stdio.h> int foo(int, int); int main(void) { printf("%d\n", foo(5,7)); return 0; } int foo(int a, int b) { return (a > b) ? a : b; } 12 7 2 Nothing. Fails to compile 0 5

7

What is the first line of code listed that contains an error? 1. #include <stdio.h> 2. 3. int main(void) 4. { 5. char name[20]; 6. 7. printf("Enter a name: "); 8. scanf("%s", $name); 9. 10. printf("The name entered is: %s\n", name); 11. return 0; 12. } 10 8 There is no error. 1 5

8

Which line number in the following program contains an error? 1. #include <stdio.h> 2. 3. // function main begins program execution 4. int main( void ) 5. { 6. int x=2, y=3, z=x+y; 7. 8. printf( "Welcome to C!\n" ) 9. }// end function main

8

Which line number in the following program contains an error? 1. #include <stdio.h> 2. 3. // function main begins program execution 4. int main( void ) 5. { 6. int x=2, y=3, z=x+y; 7. 8. printf( "Welcome to C!\n ); 9. }// end function main

8

What is the outcome/output of the following C program, if any? #include<stdio.h> void main(void){ int i = 8 , j; int *p , *q; p = &i; q = &j; j = i; printf("%d %d\n",*p,*q); j= &i; printf("%d %d\n",*p,*q); }

8 8 8 garbage

What is the outcome/output of the following C program, if any? #include<stdio.h> void main(){ int main = 80; printf("%d",main); }

80

What the function unknown() represents in the following code? #include <stdio.h> int unknown(int x) { if(x==1){return 1;} else{return 2*2*2*unknown(x-1);} } int main(void) { int a = 3; printf("%d\n", unknown(a)); } a^8 8*a 64 8^a

8^a

What is the output of the following snippet of code? #include enum month {Jan, Feb=5, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec}; int main(void) { enum month name; name = Jun; printf("%d\n", name); 5 6 9 Jun

9

What value is output by the following code snippet? int number[] = {1,2,3,4,5,6,7,8,9,10}; int value; value = ++number[1 + 2 * 3]; printf("The name entered is: %d\n", value); 7 10 6 9 8 11

9

What is the outcome/output of the following C program, if any? #include<stdio.h> void main(void) { int fun(int); int i = fun(10); printf("%d\n", --i); } int fun(int i) { return (i++); }

9 (int fun(int); declares the function as fun(). int (i) = fun(10) i is an integer and fun(10) is stored in i. int fun (int i) {return (i++);} returns 10 because i++ adds to the value after it is read. 10 is assigned to i. printf("%d\n", --i); prints 9 because it is a pre-increment)

What is the output of the following program? #include <stdio.h> int main(void) { for(int col=1;col<10;col++){ for(int row=1;row<5;row++){ printf("* "); } printf("\n"); } return 0; } 3 rows, 9 columns 10 rows, 4 columns 3 rows, 10 columns 9 rows, 4 columns

9 rows, 4 columns

Which operator listed below has right to left associativity? * <= = %

=

Which among the following is NOT a logical or relational operator? = != == || &&

= (assignment operator so it assigns values)

Which operator listed below has the lowest precedence? * ?: ++ (postfix) +

?:

#include<stdio.h> extern int x; void main(){ int y=5; printf("x is %d y is %d\n",x,y); } int x=10; a) Compile error. Variable x is not declared in main, like variable y. b) x is 10 y is 5 c) x is 5 y is 10

A

A structure can be nested inside another different structure. A. True B. False

A

A structure can be nested inside another different structure. A. True B. False

A

Comment on the output of this C code? int main() { int i, n, a = 4; scanf("%d", &n); for (i = 0; i < n; i++) a = a * 2; } • A. Logical Shift left • B. No output • C. Arithmetic Shift right • D. bitwise exclusive OR

A

Comment on the output of this C code? int main() { int i, n, a = 4; scanf("%d", &n); for (i = 0; i < n; i++) a = a * 2; } A. Logical Shift left B. No output C. Arithmetic Shift right D. bitwise exclusive OR

A

Do logical operators in C language use short circuit? A. Yes B. No C. N/A. Circuit operation applicable only for hardware.

A

Left shifting a number by 1 is always equivalent to multiplying it by 2. A. True B. False

A

Left shifting a number by 1 is always equivalent to multiplying it by 2. A. True B. False

A

Nested unions are allowed A. True B. False

A

Nested unions are allowed A. True B. False

A

One of the elements of a structure can be a pointer to the same structure. A. True B. False

A

One of the elements of a structure can be a pointer to the same structure. A. True B. False

A

One of the elements of a structure can be a variable of the same structure. A. True B. False

A

One of the elements of a structure can be a variable of the same structure. A. True B. False

A

The '->' operator can be used to access structures elements using a pointer to a structure variable only A. True B. False

A

The '->' operator can be used to access structures elements using a pointer to a structure variable only A.True B.False

A

The '.' operator can be used to access structure elements using a structure variable. A. True B. False

A

The '.' operator can be used to access structure elements using a structure variable. A. True B. False

A

Union elements can be of different sizes. A. True B. False

A

Union elements can be of different sizes. A. True B. False

A

What is the outcome/output of the following C program, if any? #include<stdio.h> void main(void) { int i=1; while() { printf("%d\n", i++); if(i>10) break; } } A. There should be a condition in the while loop B. There should be at least a semicolon in the while C. The while loop should be replaced with for loop. D. All the above E. No error

A

What is the purpose of "rb" in fopen() function used below in the code? FILE *fp; fp = fopen("source.txt", "rb"); A. open "source.txt" in binary mode for reading B. open "source.txt" in binary mode for reading and writing C. Create a new file "source.txt" for reading and writing D. None of above

A

Which of the following correctly declares an array? A. int anarray[10]; B. int anarray; C. anarray{10}; D. array anarray[10];

A

Functions can be called either by value or reference A. True B. False

A (Call by value means c = sub(a, b);. values a and b are passed. Call by reference means c = sub(&a, &b);. here address of a and b are passed)

A function may have any number of return statements, each returning it's independent values. A. True B. False

A (a function can have any number of return statements each returning a different value. return statements will not occur successively)

A function cannot be defined inside another function A. True B. False

A (can be called but CANNOT be DEFINED)

We want to test whether a value lies in the range 2 to 4 or 5 to 7. Can we do this using a switch? A. Yes B. No

A (could use the following switch(a) { case 2: case 3: case 4: /* some statements */ break; case 5: case 6: case 7: /* some statements */ break; })

Functions cannot return values of more than one variable at a time A. True B. False

A (function cannot return more than one value at a time because it gives control back to the calling function after giving a value)

A pointer to a block of memory is effectively same as an array A. True B. False

A (must use malloc function)

Is it true that too many recursive calls may result into stack overflow? A. Yes B. No

A (when a function is called its return address is stored in stack)

What does the following program do? #include <stdio.h> int main( void ) { int x; int y; int i; int j; printf( "Enter two integers in the range 1-20: " ); scanf( "%d%d", &y, &x ); for ( i = 1; i <= y; i++ ) { for ( j = 1; j <= x; j++ ) {printf( "*" ); }printf( "\n" ); } return 0; } A square of * (y rows, y columns) A square of * (y rows, x columns) A square of * (x rows, x columns) A square of * (x rows, y columns)

A square of * (y rows, x columns)

A union cannot be nested in a structure A. True B. False

B

Functions cannot return a floating point number A. Yes B. No

B

It is not possible to create an array of pointer to structures. A. True B. False

B

Point out the error in the program? #include<stdio.h> void main() { union a { int i; char ch[2]; }; union a z1 = {512}; union a z2 = {0, 2}; } A. Error: invalid union declaration B. Error: in Initializing z2 C. No error D. None of above

B

Point out the error, if any in the program. #include<stdio.h> void main(void) { int P = 10; switch(P) { case 10: printf("Case 1\n"); case 20: printf("Case 2\n"); break; case P: printf("Case 2\n"); break; } } A. Error: No default value is specified B. Error: Constant expression required at line case P: C. Error: There is no break statement in each case. D. No error will be reported.

B

The file "tools.dat" should be opened to add data to the file without discarding the current data. Which of the following is the correct statement? a) fPtr = fopen( "tools.dat", "w" ) b) fPtr = fopen( "tools.dat", "a" ) c) fPtr = fopen( "tools.dat", "r" ) d) fPtr = fopen( "tools.dat", "w+" ) e)

B

Union elements must be different sizes. A. True B. False

B

Union elements must be different sizes. A. True B. False

B

What is the similarity between a structure, union and enumeration? A. All of them let you define new values B. All of them let you define new data types C. All of them let you define new pointers D. All of them let you define new structures

B

What is the similarity between a structure, union and enumeration? A. All of them let you define new values B. All of them let you define new data types C. All of them let you define new pointers D. All of them let you define new structures

B

What will be output when you will execute following c code? #include<stdio.h> void main(void){ int x[5]={5}; printf("%d %d",x[1],x[9]); } Choose all that apply: (A) 0 Garbage (B) 0 0 (C) run time error (D) Compilation error (E) Garbage Garbage

B

Which bitwise operator is suitable for turning off a particular bit in a number? A. && operator B. & operator C. || operator D. ! operator

B

Which of the following sentences are correct about a switch loop in a C program? 1: switch is useful when we wish to check the value of variable against a particular set of values. 2: switch is useful when we wish to check whether a value falls in different ranges. 3: Compiler implements a jump table for cases used in switch. 4: It is not necessary to use a break in every switch statement. A. 1,2 B. 1,3,4 C. 2,4 D. 2

B

Which of the following statements are correct about 3 used in the program? int num[3]; num[3]=6; A. In the first statement 3 specifies a particular element, whereas in the second statement it specifies a type. B. In the first statement 3 specifies an array size, whereas in the second statement it specifies a particular element of array. C. In the first statement 3 specifies a particular element, whereas in the second statement it specifies an array size. D. In both the statement 3 specifies array size.

B

Point out the error in the program? #include<stdio.h> void main() { union a { int i; char ch[2]; }; union a z1 = {512}; union a z2 = {0, 2}; } A. Error: invalid union declaration B. Error: in Initializing z2 C. No error D. None of above

B 2 different values

It is not possible to create an array of pointer to structures. A. True B. False

B is possible

Are the expression *ptr++ and ++*ptr are same? A. True B. False

B (*ptr++ increments the pointer (not the value) ++*ptr increments the value being pointed at by ptr)

#include<stdio.h> int add(int x); void main(void) { int x=5, y =5; add(x); printf("x is %d\n",x); } int add(int x) { x = x + 10; return x; } A. x is 15 B. x is 5 C. Compile error : variable y not used None of the above

B (15 is the value of the entire function add(x), not just x. x is still 5)

Break is used to take control out of switch and continue to take control of the beginning of the switch. A. Yes B. No

B (continue can work only with loops and not with switch)

#include<stdio.h> int funcB(int x, int y) { printf("x is %d y is %d\n ",x,y); } void main(void) { int x=10, y=5; funcB(y,x); } a. x is 10 y is 5 b. x is 5 y is 10 c. Logic error d. Compile error

B (int x is given the value of y and int y is given the value of x)

Every function must return a value A. Yes B. No

B (no return value in void)

Identify logical or syntax error in the for loop, if any. #include<stdio.h> int main(void) { int x=5; for(;;x++) { printf("%d\n", x); if(x>10) break; x++; } return 0; } A.for loop requires three components B.variable x is incremented twice C.it's an infinite loop. D. All the above E. No error

B (output is 5 7 9 11 x is incremented twice)

Can we use a switch statement to switch on strings? A. Yes B. No

B (switch must either have integer constants or constant expressions)

In a function two return statements should never occur. A. Yes B. No

B (two return statements can occur but not successively)

Structures can be compared by using operators == and != Why?

Because you can have gaps between the data

In an expression using the _____ operator, bits are set to 1 if at least one of the corresponding bits in either operand is set to 1. Otherwise, the bits are set to zero.

Bitwise OR

In an expression using the _____ operator, bits are set to 1 if at least one of the corresponding bits in either operand is set to 1. Otherwise, the bits are set to zero.

Bitwise OR

In C, if you pass an array as an argument to a function, what actually gets passed? A. Value of elements in array B. First element of the array C. Base address of the array D. Address of the last element of array

C

What is the outcome of the following code segment when compiled and executed? #include<stdio.h> void main() { struct emp { char gender; int age; char name[20]; }; struct emp e1 = {'M',"David", 23}; struct emp e2 = {'M',"David", 23}; if(e1 == e2) printf("The structures are equal"); else printf("The structures are not equal"); } A. "The structures are equal" B. "The structures are not equal" is printed because garbage values fill up the remaining space in variable name C. Compile error: Structure cannot be compared using '==' D. No output

C

What is the outcome of the following code segment when compiled and executed? #include<stdio.h> void main() { struct emp { char gender; int age; char name[20]; }; struct emp e1 = {'M',"David", 23}; struct emp e2 = {'M',"David", 23}; if(e1 == e2) printf("The structures are equal"); else printf("The structures are not equal"); } A. "The structures are equal" B. "The structures are not equal" is printed because garbage values fill up the remaining space in variable name C. Compile error: Structure cannot be compared using '==' D. No output D. None of above

C

What will happen if in a C program you access an array element whose subscript exceeds the size of array? A. The element will be set to 0. B. The compiler would report an error. C. The program may crash. D. The array size would appropriately grow.

C

What's wrong with the function below int f(int a, int b) { int a; a = 20; return a; } A.Missing parenthesis in return statement B.The function should be defined as int f(int a) C.Redeclaration of a D. All the above E.None of above

C

What is the expected behavior of the following code? #include<stdio.h> int swap(int x, int y); int main(void) { int x=5, y =10; swap(x,y); printf("X is %d Y is %d\n",x,y); } int swap(int x, int y) { int temp=x; // preserve x value in temp x = y; // replace x value with y y = temp; // recall the original x value stored in temp } A. Compile error : X and Y not declared B. X is 10 Y is 5 C. X is 5 Y is 10 Y is 10 X is 5

C (if you wanted it to print x is 10 y is 5 the print statement needs to be in the swap function)

Which of the following cannot be checked in a switch-case statement? A. Character B. Integer C. Float D. enum

C (value of the "expression" in a switch-case statement must be an integer, char, short, or long. FLOAT AND DOUBLE NOT ALLOWED)

What is the outcome/output of the following C program, if any? #include<stdio.h> void main(void){ int check='2'; switch(check){ case '1': printf(" symbol 1\n"); case '2': printf("symbol 2\n"); case '3': printf("symbol 3\n"); default: printf("what ever\n"); } }

Compile Error (can't have ' ')

What is the outcome/output of the following C program, if any? #include<stdio.h> void main(void){ int check=2; switch(check){ case '1': printf(" symbol 1\n"); case '2': printf("symbol 2\n"); case '3': printf("symbol 3\n"); default: printf("what ever\n"); } }

Compile Error (can't have ' ')

What is the outcome/output of the following C program, if any? #include<stdio.h> void main(void){ int a = 10; void *ptr = &a; int *p = ptr; printf("%u",*p); printf("%u",*ptr); }

Compile Error (change void to int and output will be 1010)

What is the outcome of this code when compiled and executed? #include<stdio.h> void main() { struct emp { char name[25]; int age; float bs; }; struct emp e; e.name = "Steven"; e.age = 25; printf("%s %d\n", e.name, e.age); }

Compile Error (char [25] is not assignable)

What is the outcome/output of the following C program, if any? #define PRINT printf("Star Wars");printf(" Psycho"); #include<stdio.h> void main(void){ int x=1; if(x--) PRINT else printf("The Shawshank Redemption"); }

Compile Error (if statement needs brackets because there are two printf statements)

What is the outcome/output of the following C program, if any? #include<stdio.h> void main(){ float a; (int)a= 123.45; printf("%d",a); }

Compile Error (letter used twice in same scope, () around int, int can't be decimals)

What is the outcome/output of the following C program, if any? #include<stdio.h> void main(void){ int x=1; if(--x) printf("The Godfather"); --x; else printf("%d",x); }

Compile Error (need brackets around if statements with more than 1 arguments)

What is the outcome/output of the following C program, if any? void main(void) { int i = 1; if (i++ && (i == 1)) printf("Equal n"); else printf("Not equal\n"); }

Compile Error (needs #include <stdio.h>)

What is the outcome/output of the following C program, if any? #include<stdio.h> void main(void){ char arr[10]; arr = "world"; printf("%s",arr); }

Compile Error (should be char arr[10] = "world";)

What is the outcome/output of the following C program, if any? #include<stdio.h> void main(void){ switch(5/2*6+3.0){ case 3:printf("Beckham\n"); break; case 15:printf("Ronaldo\n "); break; case 0:printf("Messi\n"); break; default:printf("Pele\n"); } }

Compile Error (switch has to have integer values, not double)

What is the outcome/output of the following C program, if any? void main(void){int i = 0,y;int x = ++i, y = i++;printf("%d % d %d \n", x, y,i);}

Compile Error (y is declared twice)

What is the outcome/output of the following C program, if any? #include<stdio.h> void main(){ int xyz=20; int xyz; printf("%d",xyz); }

Compile error (two local variables cannot have the same name in the same scope)

What is the outcome of this code when compiled and executed? #include<stdio.h> void main() { struct emp { char name[25]; int age; float bs; }; struct emp e; e.name = "Steven"; e.age = 25; printf("%s %d\n", e.name, e.age); }

Compile error at e.name

What is the outcome/output of the following C program, if any? #include<stdio.h> void main(void) { char j=1; while(j < '5') { printf("%d, ", j); j = j+1; } printf("\n"); }

Counts 1 to 52 separated by commas (because of '5')

Point out the error, if any in the program. #include<stdio.h> void main(void) { int i = 1; switch(i) { case 1: printf("Case1\n"); break; case 1*2+4: printf("Case2\n"); break; } } A. Error: in case 1*2+4 statement B. Error: No default specified C. Error: in switch statement D. No Error

D

The keyword used to transfer control from a function back to the calling function is A. switch B. goto C. go back D. return

D

What is the net effect of this C code? Choose the best answer void main(void){ int a = 4, n, i, result = a; scanf("%d", &n); for (i = 1 ;i < n; i++) result += a; printf("result is %d",result); } What operation pattern do you see? a) result contains multiplication of a and n b) result contains addition of a and n. c) result contains repeated multiplication d) result contains the value of a

D

What is the net effect of this C code? Choose the best answer void main(void){ int a = 4, n, i, result = a; scanf("%d", &n); for (i = 1;i < n; i++) result *= a; printf("result is %d",result); } What operation pattern do you see? a) result contains multiplication of a and n b) result contains repeated multiplication c) result contains a raised to the power of n d) result contains the value of a

D

Which of the following statements correctly assigns 12 to structure member month? #include<stdio.h> struct date { int day; int month; int year; }; void main() { struct date d, *pdt; pdt = &d; } I. pdt.month = 12 II. &pdt.month = 12 III. d.month = 12 IV. pdt->month = 12 A I & III B. III & IV C. I & III D. II & IV

D

Which of the following operations can be performed on the file "NOTES.TXT" using the below code? FILE *fp; fp = fopen("NOTES.TXT", "r+"); A. Reading B. Writing C. Appending D.Read and Write

D (r+ opens an existing file for update)

What will be the output of the following snippet if value=101? switch ( value % 2 ) { case 0: printf( "Odd integer\n" ); case 1: printf( "Even integer\n" ); } Odd integer Even integer, Odd integer Odd integer, Even integer Even integer

Even integer

In an expression using the ______ operator, bits are set to 1 if exactly one of the corresponding bits in either operand is set to 1. Otherwise, the bits are set to zero.

Exclusive OR

A C program can only use functions from the standard library or user-defined functions but not both in the same program. True False

False

If an array is declared of size 10 as follows, name[10], then the array bounds checking of the C programming language will prevent a program from referring to an element that does not exit such as the 12th element. True False

False

On left shifting, the bits from the left are rotated and brought to the right and accommodated where there is empty space on the right?

False

The break statement is required in the default case of a switch selection statement. True False

False

The compiler will always store variables with the "register" storage class in a register of the CPU or cache memory. True False

False

The default case is required in the switch selection statement. True False

False

The size of a double variable is always guaranteed to be 8 bytes. True False

False

Write a statement or a set of statements to accomplish the following tasks: Calculate the value of 2.5 raised to the power of 3 using the pow function. Print the result with a precision of 2 in a field width of 10 positions. Answer: Printf("%10.2f", pow(3,2.5)); True False

False

Write a statement or a set of statements to sum the odd integers between 1 and 99 using a for statement. Answer: for(int i=1;i<=99;i++) sum+=2i+1; True False

False

Data in sequential-access files is always updated without overwriting other data

False (There is a risk of overwriting records since some are larger than others. To update a sequential file, copy all records that weren't changed to a new file and make your updates in that new file)

On left shifting, the bits from the left are rotated and brought to the right and accommodated where there is empty space on the right?

False (on left shifting, the right side bits are filled with zero)

You must explicitly use fopen to open the standard input, standard output and standard error streams.

False (these streams are opened automatically when the program is executed)

fopen

Function ________ opens a file.

Modules in C are called ______________.

Functions

What is the outcome/output of the following C program, if any? #include<stdio.h> void main(void){ int a=100; if(a < 30) { printf(" Less than 30 "); if(a > 20) printf("Greater than 20 "); else printf("Not greater than 20 "); } else if(a>10) printf("Greater than 10 "); }

Greater than 10 (Skips whole first if statement because it is false)

What is the outcome/output of the following C program, if any? #include<stdio.h> void main(void){ int a=100; if(a>30) printf(" Greater than 30 "); if(a>20) printf("Greater than 20 "); if(a>10) printf("Greater than 10 "); }

Greater than 30 Greater than 20 Greater than 10 (if statements with only 1 function don't need brackets)

What is the outcome/output of the following C program, if any? #include<stdio.h> void main(void){ int a=100; if(a>30) { printf(" Greater than 30 "); if(a<20) printf("Less than 20 "); else printf("Not less than 20 "); } else if(a>10) printf("Greater than 10 "); }

Greater than 30 Not less than 20

What is the outcome/output of the following C program, if any? #include<stdio.h> void main(void){ int a=100; if(a>30) printf(" Greater than 30 "); if(a<20) printf("Less than 20 "); else printf("Not less than 20 "); if(a>10) printf("Greater than 10 "); }

Greater than 30 Not less than 20 Greater than 10

What is the outcome/output of the following C program, if any? #include<stdio.h> void main(void) { int i = 1; switch(i) { printf("Hello\n"); case 1: printf("Hi\n"); break; case 2: printf("\nBye\n"); break; } }

Hi (switch skips straight to case 1 and the break makes the program to be exited. switch-cases do not execute any statements outside these blocks case and default so the printf("Hello\n"); does not execute)

What is the output of the below code snippet? #include <stdio.h> main() { for(;;)printf("Hello"); } Infinite loop Compile error No output Prints "Hello" once.

Infinite loop

The bitwise AND operator (&) is often used to _______ bits that is to select certain bits while zeroing others.

Mask

What is the outcome/output of the following C program, if any? #include<stdio.h> void main(void){ unsigned char c=280; switch(c){ printf("Start\t"); case 280:printf("Beckham\t"); case 24: printf("Messi\t"); default: printf("Ronaldo\t"); printf("End"); } }

Messi Ronaldo End (280 causes an overflow so it is automatically switched to 24 the highest value)

What is the output of the following program? #include <stdio.h> int main(void) { for(int col=1;col<10;col++){ for(int row=1;row<col;row++){ printf("* "); } printf("\n"); } return 0; } Negative slope triangle Rectangle Positive slope triangle

Negative slope triangle

What is the output of the following program? #include <stdio.h> int main(void) { for(int col=1;col<10;col++){ for(int row=10;row>col;row--){ printf("* "); } printf("\n"); } return 0; } Positive slope upsidedown triangle v in middle rectangle negative slope triangle

Positive slope upsidedown triangle

The two operators > and < are A. logical operators B. arithmetic operators C. equality operators D. relational operators

Relational operators

What is the outcome/output of the following C program, if any? #include<stdio.h> struct employee { char name[20]; int age; }; void modify_byVal(struct employee v) { v.age=v.age+2; } void modify_byRef(struct employee *p) { p ->age=p->age+2; } void main() { struct employee Sam = {"Sam", 35}; struct employee Mary = {"Mary", 25}; modify_byVal(Sam); modify_byRef(&Mary); printf("%s %d", Sam.name, Sam.age); printf(" "); printf("%s %d", Mary.name, Mary.age); }

Sam 35 Mary 27

What is the outcome/output of the following C program, if any? #include<stdio.h> struct employee { char name[20]; int age; }; void modify_byVal(struct employee v) { v.age=v.age+2; } void modify_byRef(struct employee *p) { p ->age=p->age+2; } void main() { struct employee Sam = {"Sam", 35}; struct employee Mary = {"Mary", 25}; modify_byVal(Sam); modify_byRef(&Mary); printf("%s %d", Sam.name, Sam.age); printf(" "); printf("%s %d", Mary.name, Mary.age); }

Sam 35 Mary 27 cant modify struct members by value, only by reference

Which logical unit of computer architecture is generally used for long term storage of information?

Secondary Storage Uni

Structured programming has shown that all C programs can be written using what forms of control? Sequence Iteration Goto Selection

Sequence, Iteration, Selection

What is the outcome/output of the following C program, if any? #include<stdio.h> void main(void){ int x=11,i; for(i=0;i<x;i+=3){ printf("Start: i is [%d]\n",i); continue; printf("End: i is [%d]\n",i); } }

Start: I is 0 Start: I is 3 Start: I is 6 Start: I is 9 (I increases by 3 until it is as close to 11 as it can get)

What is the outcome of this code when compiled and executed? #include<stdio.h> void main() { struct emp { char *name; int age; float bs; }; struct emp e; e.name = "Steven"; e.age = 25; printf("%s %d\n", e.name, e.age); }

Stephen 25

void main() { struct emp { char *name; int age; float bs; }; struct emp e; e.name = "Steven"; e.age = 25; printf("%s %d\n", e.name, e.age); }

Steven 25

Which of the following is not part of a function prototype? The parameters of the function The function's return type The function's code The function's name

The function's code

What does the following program print? 1. #include <stdio.h> 2. int main( void ) 3. { 4. int x = 1, 5. total = 0, y; 6. while ( x <= 3 ) { 7. y = x * x; 8. total += y; 9. ++x; 10. } 11. printf("Total is %d\n", total); 12. return 0; 13. } Total is 14 Total is 15 Total is 13

Total is 14

Can a main() be a recursive function, that is to say can main() call itself? True False

True

Can the C programming language be used to with 3-dimensional and higher order arrays? int array1[10][5][2]; int array2[10][5][2][12]; True False

True

For proper operations, records in random-access files should be of uniform length

True

Given a sorted list of integers stored in an array, a binary search will always do less work than a linear search when the value being searched for is not in the array. True False

True

In the C programming language, all arguments to functions are pass by value, and not pass by reference. True False

True

Is the following code snippet valid syntax? int array[5]; array[0] = 1; array[1] = 'A'; printf("%d\n", array[0]); printf("%d\n", array[1]); True False

True

Iteration and recursion can occur infinitely: An infinite loop occurs with iteration if the loop continuation test never becomes false; infinite recursion occurs if the recursion step does not reduce the problem in a manner that converges on the base case. True False

True

Iteration and recursion each involve a termination test: Iteration terminates when the loop-continuation condition fails; recursion terminates when a base case is recognized. True False

True

char string1[] = "Hello"; char string2[] = {'H', 'e', 'l', 'l', 'o', '\0' }; Does string1 contain the same value as string2? True False

True

Offset used in fseek() function call can be a negative number. A. True B. False

True (fseek() function makes the file pointer to move backwards from the current position)

We should not read after a write to a file without an intervening call to fflush(), fseek() or rewind() A. True B. False

True (should not be able to read a file after writing in it without using one of those functions to call it)

Point out the error in the program? #include<stdio.h> /* Assume there is a file called 'file.c' in c:\tc directory. */ void main() { FILE *fp; fp=fopen("c:\\tc\\file.c", "r"); if(!fp) printf("Unable to open file."); fclose(fp); } A. No error, No output. B. Program crashes at run time. C. Output: Unable to open file. D. None of above

Unable to open file (The path of file name must be given as "c: \\ tc \ file.c")

Point out the error in the program? #include<stdio.h> /* Assume there is a file called 'file.c' in c:\tc directory. */ void main() { FILE *fp; fp=fopen("c:\\tc\\file.c", "r"); if(!fp) printf("Unable to open file."); else fprintf(fp,"Hello World"); fclose(fp); } A. No error, No output. B. Program crashes at run time. C. Output: Unable to open file. D. None of above

Unable to open file (the path of file name must be given as "c: \\ tc \ file.c")

What is the output of the following program? #include <stdio.h> // function main begins program execution int main( void ) { printf( "Welcome\nto\nC!\n" ); } // end function main

Welcome to C!

What is the output of the following code. 1. #include <stdio.h> 2. 3. // function main begins program execution 4. int main( void ) 5. { 6. printf( "Welcome to" );printf( "C!\n" ); 9. }// end function main

Welcome toC!

Which of the following is the lowest access privilege for a pointer and the data it points to? a) Constant pointer to constant data b) Non-constant pointer to constant data c) Constant pointer to non-constant data d) Non-constant pointer to non-constant data d b c a

a

What is the outcome/output of the following C program, if any? #include<stdio.h> void main(void){ int m=5,n=10,q=20; if(q/n*m) printf("William Gates"); else printf(" Warren Buffet"); printf(" Carlos Slim Helu"); }

William Gates Carlos Slim Helu (last printf statement is considered outside the if else loop because there are not brackets)

Y or N: The data type of an object in memory determines the set of values it can have

Y

Y or N: The data type of an object in memory determines the size of the required memory for the data

Y

Y or N: The data type of an object in memory determines what operations that can be performed on it

Y

Are the following three statements equivalent? int* var1; int *var1; int * var1; Yes Only the last two. No Only the first two.

Yes

stderr, stdin, stdout are FILE pointers A. Yes B. No

Yes (stdio.h variable is stdin, stdout, stderr)

A program can skip the function fclose that is used to close a file?

You don't have to but you should

What is the output of the following program? #include <stdio.h> // function main begins program execution int main( void ) { printf( "\\Welcome to \"C!\"\\" ); } // end function main

\Welcome to "C!"\

What flag do you need to pass to fopen to append to an existing file instead of recreating the file?

a

What is the outcome of this code when compiled and executed? #include<stdio.h> void main() { int a=4; int b=8; if ( a & b) printf("True"); else printf("False"); }

a&b gives 0, if statement is not true, prints false

Which of the following are types of scope that an identifier can have? a) file b) block c) register d) function e) extern f) static

a, b, d

What is the outcome/output of the following C program, if any? #include<stdio.h> void main(void){ int i; for(i=0;i>=5;i++) printf("%d",i); }

blank (no error pops up, but the screen comes back blank)

the file offset

an integer value which specifies the byte in the file at which the next read or write is to occur

If the array myArray[a][b] is used to represent a table of rows and columns, which subscript would typically be used for the columns? neither both b a

b

Which variable from the code snippet below is responsible for scaling the value (i.e,. determining the desired range of the consecutive integers) of the random number being generated? int a,b,n; n = a + rand() % b; n b a

b

Which of the following are not storage class specifiers? a) auto b) block c) register d) file e) extern f) static

b, d

What is the outcome/output of the following C program, if any? #include<stdio.h> void main(void) { int x; for(x=-1; x<=10; x++) { if(x < 5) continue; else break; printf("Orlando"); } }

blank (if you want it to print Orlando, replace continue with printf("Orlando"); and the output will be OrlandoOrlandoOrlandoOrlandoOrlandoOrlando)

What is the outcome/output of the following C program, if any? #include<stdio.h> void main(void){ int check=4; switch(check){ case 1: printf("1\n"); case 2: printf("2\n"); case 3: printf("3\n"); } }

blank (there is no case 4)

What is the scope of the variable a in the following program? #include <stdio.h> int cube(int n); int b = 10; int main(void) { int a = 10; printf("%d\n", cube(a)); } int cube(int x) { int y = x * x * x; return y; } function-prototype scope function scope file scope block scope

block scope

Given the following declaration of variables, which statement is true? int* a1, a2; a) a1 is an integer type, a2 is an integer type b) a1 is is an integer type, a2 is a pointer to an integer type c) a1 is a pointer to an integer type, a2 is an integer type d) a1 is a pointer to an integer type, a2 is a pointer to an integer type

c

What is the outcome/output of the following C program, if any? #include<stdio.h> void main(void){ int x=123; int i= printf("c" "++"); for(x=0;x<=i;x++){ printf("%x ",x); } }

c++0 1 2 3

Given struct card { char *face; char *suit; } c, *cPtr; cPtr= &c; Which of following is the proper syntax to access the member face? *cPtr->face cPtr.face cPtr->face card->face

cPtr->face

Given struct card { char *face; char *suit; } c, *cPtr; cPtr= &c; Which of following is the proper syntax to access the member face? *cPtr->face cPtr.face cPtr->face card->face

cPtr->face

Which <math.h> function rounds x to the smallest integer not less than x? abs(x) floor(x) ceil(x) log(x)

ceil(x)

Which of the following is the highest access privilege for a pointer and the data it points to? a) Constant pointer to constant data b) Non-constant pointer to constant data c) Constant pointer to non-constant data d) Non-constant pointer to non-constant data d c a b

d

What is the output of the following program if the user enter 25, (age =25). #include <stdio.h> int main( void ) { int age, ageRange; printf(" Please enter your age to see the consered discount for you. "); scanf("%d", &age); if (age<18) ageRange=1; else if (age>=18 && age< 30) ageRange=2; else if (age>=30 && age<50) ageRange=3; else if (age>=50 && age<65) ageRange=4; else ageRange=5; switch(ageRange){ case 1:printf("discount 10 Percent.\n"); break; case 2:printf("discount 15 Percent.\n"); case 3:printf("discount 20 Percent.\n"); break; printf("discount 25 Percent.\n"); case 4: default: printf("discount 50 Percent.\n"); break; } return 0; } discount 25 Percent. discount 20 Percent. discount 15 Percent. discount 20 Percent. discount 15 Percent. discount 20 Percent. discount 15 Percent.

discount 15 Percent. discount 20 Percent.

In the following chunk of code, if we want to execute the line y = &x, what should be the data type for y? double x = 3.14; _____ y; y = &x; int * int double double *

double*

If the file 'source.txt' contains a line "Be my friend" which of the following will be the output of below program? #include<stdio.h> void main() { FILE *fs, *ft; char c[10]; fs = fopen("source.txt", "r"); c[0] = getc(fs); fseek(fs, 0, SEEK_END); fseek(fs, -3L, SEEK_CUR); fgets(c, 5, fs); puts(c); }

end (Fseek(fs, 0, SEEK_END); moves the file pointer to the end of the file Fseek(fs, -3L, SEEK_CUR); moves the file pointer backward by 3 characters Fgets(c, 5, fs); red the file from the current position of the file pointer. It contains the last 3 characters of "Be my friend" and therefore "end")

What is the output of the following code: #include <stdio.h> void sub(int a, int b); int main(void) { printf("%d", sub(3,2)); return 0; } void sub(int a, int b) { return a+b; } 1 sub(3,2) 5 error

error

Which files will get closed through the fclose() in the following program? #include<stdio.h> void main() { FILE *fs, *ft, *fp; fp = fopen("A.C", "r"); fs = fopen("B.C", "r"); ft = fopen("C.C", "r"); fclose(fp, fs, ft); }

error in fclose

In an expression using the ______ operator, bits are set to 1 if exactly one of the corresponding bits in either operand is set to 1. Otherwise, the bits are set to zero.

exclusive OR

What is the scope of the variable b in the following program? #include <stdio.h> int cube(int n); int b = 10; int main(void) { int a = 10; printf("%d\n", cube(a)); } int cube(int x) { int y = x * x * x; return y; } function scope block scope function-prototype scope file scope

file scope

Which <math.h> function rounds x to the largest integer not greater than x? ceil() mod(x) abs() floor(x)

floor(x)

the function fprintf is equivalent to printf except...

fprintf also receives as an argument a pointer to a file which writing will be written

Function ______________ re positions the file position pointer to a specific location in the file.

fseek() (used to move file pointer of a file to a specific position

What is the scope of the identifier here on line 10 of the program below? 1) #include <stdio.h> 2) 3) int main(void) 4) { 5) int a = 5; 6) // Don't write code like this! 7) goto here; 8) a = a * 2; 9) 10) here: 11) a = a * 3; 12) 13) printf("Value of a: %d\n", a); 14) } function-prototype scope file scope function scope block scope

function scope

Which is the only type of scope that can be assigned to a label? file scope function-prototype scope function scope block scope

function scope

What is the scope of the variable n in the following program? #include <stdio.h> int cube(int n); int b = 10; int main(void) { int a = 10; printf("%d\n", cube(a)); } int cube(int x) { int y = x * x * x; return y; } file scope function-prototype scope function scope block scope

function-prototype scope

What is the outcome/output of the following C program, if any? #include<stdio.h> void main(){ int x=100,y=20,z=5; printf("%d %d %d"); }

garbage (need , x, y, z after the %ds)

What is the outcome/output of the following C program, if any? #include<stdio.h> void main(void){ int i = 3; int *j; int **k; j = &i; k = &j; printf("%d %d\n",j,k); printf("%p %p\n",j,k); }

garbage garbage garbage garbage

What is the consistent outcome/output of the following C program, if any? #include<stdio.h> void main(void) { int arr[5], i=0; while(i<5) arr[i]=++i; for(i=0; i<5; i++) printf("%d, ", arr[i]); } Pay attention to value of i

garbage, 1, 2, 3 ,4

What is the output of the following snippet? For ( x = 100, x >= 1, x++ ) printf( "%d\n", x ); 100 infinite loop integers from 1 to 100. 1

infinite loop

file control block

info that the operating system uses to administer a particular file

What should be placed in the blank so that bPtr can be used to modify the value of the variable a? int a = 10; int *aPtr; ___ bPtr; aPtr = &a; bPtr = &aPtr; **bPtr = 15; int * int int ** int ***

int**

Is the following a legal or illegal identifier in C? "different"

legal

Is the following a legal or illegal identifier in C? "integr_21"

legal

What will be the output of the following program ? #include "stdio.h" int main(void) { int i=21; do { printf( "%d ", i ); i += 1; if ( i % 2 == 1 ) continue; } while ( i< 100 ); return 0; } list of even integers from 21 to 99 (inclusive) list of integers from 21 to 99 (inclusive) list of odd integers from 21 to 99 (inclusive) infinite loop

list of integers from 21 to 99 (inclusive)

Which of the following identifier names are invalid? long 10sdigit total$amount aReallyLongVariableNameVar Variable_one

long, 10sdigit, total$amount

Which of the following is not a valid function name? my-Power my_Power my4Power myPower

my-Power

If a linear search is performed against an array containing n items and is looking for the value of key, how many times must the comparison array[j]==key be made if the key is not to be found in the array where j goes from 0 to (n-1)? (n - 1) times n times Unable to tell key times

n times

What is the outcome/output of the following C program, if any? #include<stdio.h> int main(){ long int 1a=5l; printf("%ld",1a); }

no output (cannot have 1 in front of a)

Which output would be reasonable for the following code snippet? char str[] = "Hello"; printf("%c ", str[4]); printf("%s ", str); printf("%p\n", str); l Hello Hello l Hello 0x7ffe99be308a o Hello Hello o Hello 0x7ffe99be308a

o Hello 0x7ffe99be308a

a

open a file for writing at the end of the file-- write operations begin at end of file

a+

open an existing file for reading and updating - all write operations happen at the end of the file

r+

open an existing file for update (reading and writing)

#include<stdio.h> void main(void){ int x=4; while(3){ do{ printf("%d",x); } while(0); } ; }

prints 4 continuously

Which of the following functions are in the C standard math library? sin() pow() cos() cube() cuberoot()

sin(), pow(), cos()

Given union values { char w; float x; double y; }; Which of the following will work? union values v = { 1.27 }; union values v = { '1.27'}; union values v = { 1 }; all the above; none of the above

union values v = {1} (union values v = {'1'} would work too. an ASCII value would be returned)

Given union values { char w; float x; double y; }; Which of the following will work? union values v = { 1.27 }; union values v = { '1.27'}; union values v = { 1 }; all the above; none of the above

union values v = {1}; must be able to fit in 1 byte {'1'} would also work, would be ascii value

Will the following functions work? int f1(int a, int b) { return ( f2(20) ); } int f2(int a) { return (a*a); }

yes (20*20=400)

Write a single C statement to accomplish the following: Assign the sum of x and y to z and increment the value of x by 1 after the calculation. z=(x++)+y; x++; z=x+y; z=x+y+(++ x); z=x+y+(x+1);

z=(x++)+y;

Which of the following is a logical OR operator? & | || &&

||

True.

(True or False) Function fprintf can write to the standard output.

False. These three streams are opened automatically by C when the program execution begins.

(True or False) You must explicity use fopen to open the standard input, standard output and standard error streams.

What is the output of the following code? ( Assume that there is no error when the file file.txt is opened.) #include <stdio.h> int main(){ FILE * fp; char file_name[20]="file.txt"; fp = fopen (file_name, "wb"); fprintf(fp, "%s", "11111"); fseek(fp, 3, SEEK_SET); fprintf(fp, "%s", "22222"); fseek(fp, -5, SEEK_END); fprintf(fp, "%s", "33333"); fclose(fp); return(0); }

11133333

What is the output of the following code? ( Assume that there is no error when the file file.txt is opened.) #include <stdio.h> int main(){ FILE * fp; char file_name[20]="file.txt"; fp = fopen (file_name, "wb"); fprintf(fp, "%s", "123456789"); fseek(fp, 10, SEEK_SET); fprintf(fp, "%s", "abcdefgh"); fclose(fp); return(0); }

123abcdefgh

In which line of the following code the first error is appeared (if any)? 1. #include <stdio.h> 2. struct clientData { 3. unsigned int acctNum; // account number 4. char lastName[15]; // account last name 5. char firstName[10]; // account first name 6. double balance; // account balance 7. }; 8. int main(void) 9. { 10. FILE *cfPtr; 11. cfPtr = fopen("accounts.dat", "wb"; 12. struct clientData blankClient = {0, "", "", 0.0}; 13. 14. for (unsigned int i = 1; i <= 100; ++i) { 15. fwrite(blankClient, sizeof(struct clientData), 1, cfPtr); 16. } 17. fclose (cfPtr); // fclose closes the file 18. } 19. }

15

Which line number in the following program contains an error? 1. #include <stdio.h> 2. 3. / function main begins program execution 4. int main( void ) 5. { 6. printf( "Welcome to C!\n" ); 7. } // end function main

3

Count the number of the statements in the following code: #include <stdio.h> // function main begins program execution int main( void ) { int A=1,B=2,C=3; A=B+1;B=A+1; printf( "%d", A+B); } // end function main

4

Which line number in the following program contains an error? 1. #include <stdio.h> 2. 3. // function main begins program execution 4. int main 5. { 6. printf( "Welcome to C!\n" ); 7. } // end function main

4

Which line number in the following program contains an error? 1. #include <stdio.h> 2. 3. // function main begins program execution 4. int main( void ) 5. { 6. int x=2, 7. printf( "Welcome to C!\n" ); 8. }// end function main

6

Which line number in the following program contains an error? 1. #include <stdio.h> 2. 3. // function main begins program execution 4. int main( void ) 5. { 6. printf( "Welcome to C!\n" ) 7. } // end function main

6

What is the output of this program by manipulating the text file? #include <stdio.h> int main() { FILE* p; int c; int n = 0; p = fopen("myfile.txt", "r"); if (p == NULL) perror("Error opening file"); else { do { c = getc(p); if (c == '$') n++; } while (c != EOF); fclose(p); printf("%d\n", n); } return 0; }

Error opening file Count of '$' symbol

Which of the followings is true about FILE *fp?

FILE is a structure and fp is a pointer to the structure of FILE type

Function fopen reads a line from a specified file.

False

Function fscanf cannot be used to read data from the standard input.

False

If the file position pointer points to a location in a sequential file other than the beginning of the file, the file must be closed and reopened to read from the beginning of the file.

False

You must explicitly use fopen to open the standard input, standard output and standard error streams.

False

T/F - If the file position pointer points to a location in a sequential file other than the beginning of the file, the file must be closed and reopened to read from the beginning of the file

False - Function rewind can be used to reposition the file position pointer to the beginning of the file

T/F - Data in sequential access files is always updated without overwriting other data

False - In most cases, sequential file records are not of uniform length, therefore it's possible that updating a record will cause other data to be overwritten

T/F - Records in random access files are not of uniform length

False - Records in a random access file are normally of uniform length

T/F - A program must explicitly call fclose() to close a file

False - The files will be closed automatically when program terminates, but all files should be explicitly closed with fclose

T/F - Function fseek may seek only relative to the beginning of the file

False - it is possible to seek from the beginning of the file, the end of the file, and from the current location in the file.

fclose

Function ________ closes a file.

fread

Function ________ is normally used when reading data from a file in random-access applications.

fgetc

Function ________ reads a character from a specified file.

fgets

Function ________ reads a line from a specified file.

fseek

Function _________ repositions the file position pointer to a specific location in the file.

What type of programming language uses generally uses only 0's and 1's for writing programs?

Machine Language

Which logical unit of computer architecture typically stores information for rapid access and generally contains volatile information that is lost when the computer is powered off?

Memory Unit

When fopen() is not able to open a file, it returns .....

NULL

if an error occurs while opening a file in any mode, fopen returns

NULL

Is it correct to say that in the following code segment, the file "tools.dat" is opened to add data to the file without discarding the current data. if ( ( tfPtr = fopen( "tools.dat", "w" ) ) != NULL ) {}

No

fscanf

The ________ function reads data from a file in a manner similar to how scanf reads from standard in.

T/F - It is not necessary to search through all the records in a random access file to find a specific file

True

T/F - fprintf can write to the standard output

True

The following statement should read a record from the file "payables.dat". File pointer payPtr refers to this file, and file pointer recPtr refers to the file "receive.dat": scanf( recPtr, "%d%s%d\n", &account, company, &amount ); Is there any error in the program segment above?

True

What is the output of this program by manipulating the text file? (Assume the text file has been already created.) #include <stdio.h> int main(){ char c; FILE * pFile; pFile = fopen("file.txt", "w"); for (c = 'a'; c <= 'g'; c+=2) { putc(c+1, pFile); } fclose(pFile); return 0; }

bdfh

fgets and fputs functions respectively

can be used to read a line from a file and write a line to a file

if function fclose is not called explicitly, the operating system will

close the file once the program is terminated

streams provide

communication channels between files and programs

w+

create a file for reading and writing- if file already exists, discard current contents

wb+

create a file for update in binary mode - if file already exists, discard current contents

w

create a file for writing - if the file already exists, discard current contents

wb

create a file for writing in binary mode- if file exists, discard current contents

feof

determines whether end of file indicator shows that there is nothing more to read in the file

Is the following a legal or illegal identifier in C? "a_variable"

legal

rb

open an existing file reading in binary mode

rb+

open existing file for updating in reading and writing in binary mode

fgets

reads a line from a specified file

opening a file...`

returns a pointer to a FILE structure that contains info used to process the file

sequential access files

sequential access with fprintf and fscanf is not usually to update the file- instead, file is usually rewritten

fseek

sets file position pointer a specific position in the file, to write data at a specific location

the standard input, output, and error are manipulated using

stdin, stdout, and stderr

fwrite

transfers a specified number of bytes beginning at a specified location in memory to a file

fread

transfers a specified number of bytes from the location specified by the file position pointer to an area in memory beginning with a specified address


Set pelajaran terkait

美国当代英语语料库(COCA) 500-13

View Set

FoRT practice test (multiple choice only)

View Set

Chapter 08 - Understanding Human Sexuality - Hyde - study guide

View Set

Essentials of Leadership Chapter 8 Quiz

View Set