Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

EXPERT HELP THANKS! Question 1 What does the following code do: #include int main(void) { char str[]; int rc = scanf(%s , str); if (rc

EXPERT HELP THANKS!

Question 1

What does the following code do:

#include int main(void) { char str[]; int rc = scanf("%s ", str); if (rc == 1) printf("%s ", str); return 0; }

Question 1 options:

A

None of the above.

B

It crashes.

C

It reads a string from stdin and prints it to stdout.

D

It does not compile.

Question 2

What does this program print:

#include int main(int argc, char ** argv) { int res = sizeof(argc) == sizeof(int) && sizeof(argv) == sizeof(char **); if (res) printf("true "); else printf("false "); return 0; }

Question 2 options:

A

The result depends on the machine on which it is run.

B

It prints "true."

C

The result depends on what is in the command line.

D

It crashes.

E

None of the above.

F

It does not compile.

G

It prints "false."

Question 3

If the command line is

./my_pgm -t 10 my_data.dat

what is in argv[2] when ./my_pgm is run?

Question 3 options:

A

'\0'

B

None of the above.

C

NULL

D

The address of the string literal "my_data.dat".

E

The address of the string literal "10".

F

'1'

G

The address of the string literal "-t".

H

The integer 10.

Question 4

Should you use scanf or sscanf to solve this problem?

Read a sequence of integers from stdin until EOF and print the absolute value of each number read.

Question 4 options:

A

scanf

B

sscanf

Question 5

What does the following code print on a 64-bit machine?

#include void printSize(char p[]) { printf("%zu ", sizeof(p)); } int main(void) { char p[] = "Hello, World!"; printSize(p); return 0; }

Question 5 options:

A

It does not compile.

B

8

C

14

D

It crashes.

Question 6

Does this program read the command-line arguments?

int main(void) { ... }

Question 6 options:

A

Yes.

B

No.

C

Maybe.

Question 7

Does the following code read the command-line arguments?

int main(void) { int argc = 3; char const * argv[] = {"./my_pgm", "-t", "12"}; int n = 10; /* default */ int err = parseArgs(argc, argv, &n); printf("%d ", n); return err; }

Question 7 options:

A

It would, but the initializer of argv causes a syntax error.

B

Yes.

C

No.

D

It depends on what is in function parseArgs.

Question 8

What does the following program do?

#include int main(void) { double pi = 3.14159; double x; int rc; while ((rc = scanf("%lg", &x)) != EOF) { if (rc != 1) return -1; double diff = x - pi; if (-0.1 < diff && diff < 0.1) { printf("%g is close enough to %g ", x, pi); return 0; } } return 0; }

Question 8 options:

A

None of the above.

B

It reads a double from the command line.

C

It computes an approximation to {"version":"1.1","math":""} by Taylor series expansion.

D

It reads doubles from stdin until either EOF is reached or a number sufficiently close to {"version":"1.1","math":""} or something that is not a doubleis entered.

Question 9

What do scanf and sscanf return?

Question 9 options:

A

They return the number of characters read.

B

They return the number of successful assignments performed.

C

They return nothing.

D

They return 0 if successful and -1 otherwise.

Question 10

What is the problem with this code?

#include int main(void) { int * p; int rc = scanf("%d", p); return rc != 1; }

Question 10 options:

A

The return expression gives a syntax error.

B

It works just fine.

C

The pointer p does not point to a valid address.

D

The address of p should be passed to scanf (as in &p).

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Theory Icdt 97 6th International Conference Delphi Greece January 8 10 1997 Proceedings Lncs 1186

Authors: Foto N. Afrati ,Phokion G. Kolaitis

1st Edition

3540622225, 978-3540622222

More Books

Students also viewed these Databases questions

Question

=+27-1 Describe operant conditioning.

Answered: 1 week ago