Question: Consider the following C program. A macro is defined to calculate the cube of a input parameter. #define CUBE(x) x * x * x int

Consider the following C program. A macro is defined to calculate the cube of a input parameter.

#define CUBE(x) x * x * x

int main() {

int k = CUBE(4);

int m = CUBE(4 + 3 + 2);

}

What is the pre-processed code in main()? Do you think the macro has a flaw? If yes, fix the macro so it always work correctly. If you think the macro has no flaw, just write 'No flaw'.

Consider the following C program.

Consider the following C program. A macro is defined to calculate the

Suppose the output of the first printf (line 4) is 3200 5600 7000 8000

(Recall that printing a pointer with %p outputs the content/value of the pointer, which is the address of its pointee, in Hex. To simplify, here we assume it prints in decimal)

Assume short, int and double takes 2, 4 and 8 bytes respectively. What is the output of the program in line 5 and line 8 (in decimal)?

Consider the following C code.

cube of a input parameter. #define CUBE(x) x * x * x

Replace ??? with a proper call, involving msg or p, so that the output is substring "llo orld".

List 3 different ways to call.

Note that replacing ??? with "llo orld" is NOT acceptable. Also, you cannot use more than one arithmetic operator in each answer.

main(){ int a; short b; char c; double d; int * pint = &a; short * pShort = &b; char * pChar = &c; double * pDouble = &d; printf("%p % % %p ", pChar, pShort,pInt, pDouble); // line 4 printf("%p%p%p%p ", pChar+1, pShort+1,pInt+1, pDouble+1); // line 5 pInt++; pShort++; pChar ++; pDouble++; pint += 4; pShort +=4; pChar +=4; pDouble +=4; printf("%p%p%p%p ", pChar+1, pShort+1,pInt+1, pDouble+1); // line 8 int main() { char msg[] = "Hello World"; char * p = msg; printf("%s", ???); }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!