Question: (a) Write a C program that will print out all command line arguments, in reverse order, one per line. Prefix each line with its index.

 (a) Write a C program that will print out all commandline arguments, in reverse order, one per line. Prefix each line with

(a) Write a C program that will print out all command line arguments, in reverse order, one per line. Prefix each line with its index. (b) Consider this C code snippet: int a= 100: int b= 42: int* p= &a: int* q= &b: *p= *q+10: p = q: printf ("%d %d ", a, *p): When this code is executed, what numbers will it print? (c) Consider this C program int main(int argc, char** argv) { char* target = "Apple": char word [100]: printf ("Enter a word: "}: scanf ("%s", &line): if(word==target){ printf("same "): } else { printf("different "): } return 0: } This program does not work as expected. Explain why, and suggest how it can be fixed (d) During your pracwork you have used the C string-duplicate function, whose signature is: char* strdup(char* source) Write an implementation of strdup (e) The questions in this part are about the C pre-processor. i. What is the output of this program? ii. Conditional compilation controls which parts of a source file will be compiled. In the following program code, is the file program.h included twice in program.c? Explain why, or why not. Write a recursive C function, mystrcmp, that is passed pointers to two null-terminated strings, a, and b. Your function must return -1, if a is less than b, 0 if a is the same as b, and +1 if a is greater then b. You may assume that a and b are not NULL. You must not call any other functions

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!