Vous êtes sur la page 1sur 3

Assignment

4
Mat Morash, 7723671

Question 1:

This program will just print the number 4 because the program prints the
pointer *(a+3) which is actually pointing to the fourth number in the array a. If the
program had wanted to print the first value in the array it would have printed the
pointer *(a).

Question 2:

This segment of code will have multiple errors, which will not allow it to
compile properly. The first error being that the integer i is not declared in the code
and is used in the for loop. A second error is that a line used is a=b. This line cannot
compile because the variables a and b are not regular variables, they are arrays
which means they have more then one value. They cannot be equal to each other
therefor this code will not run.

Question 3:

This program will print the number 5, which is the 5th value in the array. The
program requests to print the pointer *(p+1) but the p is actually equal to a+3 and
therefor the program requests to print the expression *(a+3+1)=*(a+4). That
expression means print the 5th value in the array which is 5.

Question 4:

This program will compile and it will print the two columns; one with the
numbers 1, 2, 3 and the other with 1, -2, -3. This happens because the pointer b*=a*
means that just the first value of a is equal to the first value of b. the for loop
continues regularly until three numbers of each array are printed.













Question 8:

This program prompts the user to input an integer to represent the size of an array
in this program. The program will then use random numbers to generate the values
inside the array. The function Getevennumbers will then find all of the even
numbers inside the array and print them back out.

I/O Description:





Even numbers within
Size of Array

array


Flow Chart:


*GetevenNumbers
Declare variable I, N, r.

Declare int* Numbers=

malloc(sizeof(int)*N),

Print: Enter a positive

integer

Declare variable i, j=0

Scan and assign to

variable N.
For loop: (i=0; i<N; i++)


Declare a[N]

If modulus of a[i]/2 is

equal to 0,
Numbers[j]=a[i] and print

For loop: (i=0; i<N; i++)
value


a[i]= random numbers

Return Numbers.


Print a[i]



Print Even numbers are



Call function
*GetevenNumbers



When the integer 4 is entered:



When the integer 15 is entered:

Vous aimerez peut-être aussi