Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(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.

image text in transcribedimage text in transcribed

(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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

define unbiasedness

Answered: 1 week ago