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

#include<stdio.h> void shakespeares(void); void chipotle(int); int guac = 100; i

ID: 3830190 • Letter: #

Question

#include<stdio.h>          

void shakespeares(void);

void chipotle(int);

int guac = 100;

int main(void){

printf(“%d”,guac);
int guac =200;

int salsa =400;

printf(“%d”,guac);

if(salsa<500){

int guac = 300;

}

printf(“%d”,guac);

printf(“%d”,guac--);

shakespeares ();

shakespeares ();

chipotle ();

chipotle ();

shakespeares ();

printf(“%d”,guac);

return 0;

}

Void chipotle(){

printf(“%d”,guac);

guac++;

printf(“%d”,guac);

printf(“%d”,++guac);

}

Void shakespeares()

{

Static int guac = 250;

printf(“%d”,guac);

--guac;

printf(“%d”,guac);

}

1.Output of all printfs in the code ?

2. How many functions ?

3. What is the lib for random ()?

4. What is the lib for atoi () and malloc ()?

5. What is the lib for isalnum ()?

6. What is the lib for strcmp()?

Int today=6;

Int yest=5;

Int tomo=7;

tomo = (today >yest)? tomo: yest;

7. what is tomo?

1+rand()%6

8. What are the possible range of numbers?
9. if rand returns 46, what is the value?

./a.out 44 input.data output.txt

A. What is argc or the count?

B. What is argv[2]?

C. What is argv[1]? What is atoi(argv[1])?

Void starbucks(int [], int, int*);

Int main(){

Int chai=5;

Int latte=20;

Int mocha [5] ={10,20,30,40,50};

Starbucks(mocha, chai, &latte);

Printf(“%d”,latte); //170

Return 0;

}

Void starbucks(int x[],int y, int *z)

{

Int i;

For(i=0;i<y;i++){

*z+=x[i];

}

10. What is the value in printf?

Int c=10;

Int b = c++ * 7 +20-33/11*4-2/2;

11. What is b?

Pointer math and pointer notation.

If aptr starting address is 2000 and int is 2 bytes long

int *aptr=malloc(sizeof(int)*5);
int a=0,i;

for(i=0;i<5;i++){

*aptr= i*5;

aptr++;

}

Aptr--;

12. What is *aptr + *aptr = ?

13. What is printf(“%p”,aptr); ?

Explanation / Answer

1. Some compilation error with the code, and corrected those here. Also the function chipotle() is declared with one int argument and while defining the function it is missing. So I have shared the two version of the code , one which takes int argument and the other which doesnot take.

first version:

#include<stdio.h>

void shakespeares(void);

void chipotle();

int guac = 100;

int main(void){

printf("%d ",guac);
int guac =200;

int salsa =400;

printf("d ",guac);

if(salsa<500){

int guac = 300;

}

printf("%d ",guac);

printf("%d ",guac--);

shakespeares ();

shakespeares ();

chipotle ();

chipotle ();

shakespeares ();

printf("%d",guac);

return 0;
}

void chipotle(){

printf("%d ",guac);

guac++;

printf("%d ",guac);

printf("%d ",++guac);

}

void shakespeares()

{

static int guac = 250;

printf("%d ",guac);

--guac;

printf("%d ",guac);

}

output:

[root@rhel7test ~]# ./a.out
100 d 200 200 250 249
249 248
100 101 102
102 103 104
248 247
199

second version:

#include<stdio.h>

void shakespeares(void);

void chipotle(int);

int guac = 100;

int main(void){

printf("%d ",guac);
int guac =200;

int salsa =400;

printf("d ",guac);

if(salsa<500){

int guac = 300;

}

printf("%d ",guac);

printf("%d ",guac--);

shakespeares ();

shakespeares ();

chipotle (guac);

chipotle (guac);

shakespeares ();

printf("%d",guac);

return 0;
}

void chipotle(int guac)
{
printf("%d ",guac);

guac++;

printf("%d ",guac);

printf("%d ",++guac);

}

void shakespeares()

{

static int guac = 250;

printf("%d ",guac);

--guac;

printf("%d ",guac);

}

output:

[root@rhel7test ~]# ./a.out
100 d 200 200 250 249
249 248
199 200 201
199 200 201
248 247
199

2.2 fuctions guac and shakespeare and one main .

3.stdio.h

4. atoi - stdlib, malloc -stdio
5. isalnum- stdio.h
6. strcmp- string.h
7. Ans = 7 (as today >yest)
8. range is 1 to 6, as rand()%6 can output 0,1,2,3,4,5
9.5

./a.out 44 input.data output.txt

argc= 4

argv[2]= input.data

argv[1] = 44 (string)

atoi(argv[1])= 44 (int)


10. 170

There was some compilation error. So corrected those.

#include<stdio.h>

void starbucks(int [], int, int*);

int main(){

int chai=5;

int latte=20;

int mocha [5] ={10,20,30,40,50};

starbucks(mocha, chai, &latte);

printf("%d",latte); //170

return 0;

}

void starbucks(int x[],int y, int *z)

{

int i;

for(i=0;i<y;i++){

*z+=x[i];

}
}

11.777
12.i is getting incremented till 4, and aptr pointer is getting incremented. So the last element will have value = 4*5=20.

*aptr after the for loop is 20.

hence *aptr+*aptr=40.

40

13.There are 5 integers in the array. each takes 2 bytes. hence total 10 bytes from the starting point (2000)
2010