Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

EXPERT HELP THANKS! Question 1 What does the following code do: #include <stdio.

ID: 3859926 • Letter: E

Question

EXPERT HELP THANKS!

Question 1

What does the following code do:

#include <stdio.h>

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

Question 1 options:

None of the above.

It crashes.

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

It does not compile.

Question 2

What does this program print:

#include <stdio.h>

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:

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

It prints "true."

The result depends on what is in the command line.

It crashes.

None of the above.

It does not compile.

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:

''

None of the above.

NULL

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

The address of the string literal "10".

'1'

The address of the string literal "-t".

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:

scanf

sscanf

Question 5

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

#include <stdio.h>

void printSize(char p[]) {
printf("%zu ", sizeof(p));
}

int main(void) {
char p[] = "Hello, World!";
printSize(p);
return 0;
}

Question 5 options:

It does not compile.

8

14

It crashes.

Question 6

Does this program read the command-line arguments?

int main(void) {
...
}

Question 6 options:

Yes.

No.

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:

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

Yes.

No.

It depends on what is in function parseArgs.

Question 8

What does the following program do?

#include <stdio.h>

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:

None of the above.

It reads a double from the command line.

It computes an approximation to {"version":"1.1","math":"&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;&lt;/mi&gt;&lt;/math&gt;"} by Taylor series expansion.

It reads doubles from stdin until either EOF is reached or a number sufficiently close to {"version":"1.1","math":"&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;&lt;/mi&gt;&lt;/math&gt;"} or something that is not a doubleis entered.

Question 9

What do scanf and sscanf return?

Question 9 options:

They return the number of characters read.

They return the number of successful assignments performed.

They return nothing.

They return 0 if successful and -1 otherwise.

Question 10

What is the problem with this code?

#include <stdio.h>

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

Question 10 options:

The return expression gives a syntax error.

It works just fine.

The pointer p does not point to a valid address.

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

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.

Explanation / Answer

Question 1

What does the following code do:

#include <stdio.h>

int main(void) {
char str[]; // Here array size missing in str
int rc = scanf("%s ", str);
if (rc == 1)
    printf("%s ", str);
return 0;
}
Answer: option D. It does not compile.

Question 2

What does this program print:

#include <stdio.h>

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;
}

Answer: option B. It prints true

Question 5

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

#include <stdio.h>

void printSize(char p[]) {
printf("%zu ", sizeof(p));
}

int main(void) {
char p[] = "Hello, World!";
printSize(p);
return 0;
}

Output: 4

Answer: None of given Options

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;
}

Answer: option D.It depends on what is in function parseArgs.

Question 10

What is the problem with this code?

#include <stdio.h>

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

Answer: option D. The address of p should be passed to scanf (as in &p).

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote