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

How many iterations of the for loop does this program perform? int main(void) {

ID: 3795335 • Letter: H

Question

How many iterations of the for loop does this program perform?

int main(void) {
int a[] = {1, 2, 3, 4};
int i;
for (i = 0; i < 4; i++) {
    if (a[i] < 0) return 1;
    else return 0;
}
return 0;
}

Question 1 options:

No iterations.

The program crashes.

One.

The program does not compile.

Four.

Question 2

What does the following program do?

Question 2 options:

It crashes when it is run because no memory is reserved for the array.

It does not compile.

It fills the array with the squares of the integers from 1 to 10.

It fills the array with the first 10 powers of 2.

Question 3

What's the problem with this code?

Question 3 options:

The main problem is that the loop accesses a non-existing a[5]. This will cause some memory location to be inadvertently written. The secondary problem is that a[0] is left uninitialized.

It doesn't compile because one cannot declare an int variable and an int array on the same line.

There is no problem. The code will run just fine.

It crashes because a[1] is accessed before a[0].

Question 4

If a is declared with

what value does sizeof(a) have?

Question 4 options:

14

Whatever is the size of a pointer to an integer.

10

10*sizeof(int)

Question 5

What does the following program do?

Question 5 options:

It prints 1 2 3 4.

The program incurs a segmentation fault when run.

It does not compile. You cannot copy arrays like that.

It does not compile. You cannot print an entire array like that.

question 6

Arrays are just pointers in disguise.

Question 6 options:

Question 7

Declaring too large an array in a function may cause a stack overflow when the function is called.

Question 7 options:

Question 8

What does the following program do?

Question 8 options:

It crashes because main can only return 0.

It returns 3.

It returns 4.

It does not compile.

Question 9

What does the following program do?

Question 9 options:

It does not compile.

It prints: 1 1 1 1 1

Prints: 1 2 3 4 5.

It crashes because it causes a segmentation fault.

Question 10

What does the following program do?

Question 10 options:

It crashes because p != a+n accesses an address that isout of bounds.

It doesn't compile. You cannot assign an array to a pointer because they are of different types.

It prints nonsense because %d is for integers, while p is a pointer.

It prints: 0 1 2 3 4

A

No iterations.

B

The program crashes.

C

One.

D

The program does not compile.

E

Four.

Explanation / Answer

Q1:

C.One

Explanation:When it enters in loop for first time,it checks condition then it fails and cause to return 0.Hence it terminates loop as well as code

====================================================================

Question 2:

Ans:

It crashes when it is run because no memory is reserved for the array.

expanation:It is neccessary to give size of array otherwise causes syntax error

===============================================================================

Q3:

Ans:

There is no problem. The code will run just fine.

Explanation :As there is no syntax error ,code runs fine .There may be run time error or exception when we try do operations on array

=================================================================================

Q.4

Ans:d 10sizeof(int)

Expanation:Above will give 40 because 10 * 4(size of int is 4) which is same as sizeof(a) as a is array of 10 integers

A

It crashes when it is run because no memory is reserved for the array.

expanation:It is neccessary to give size of array otherwise causes syntax error

===============================================================================

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