Sie sind auf Seite 1von 2

C Refresher Module

Assignment 1:

Q1 Write a C program to swap numbers in cyclic order using Pointers


Q2 Write a program to compare two strings using pointers.

Q3.Create two swap functions (Swaps the two values)

a. swap(a, b) a, b are integers

b. swap(a, b) a, b are pointers

Put a = 2, b = 3 and then assert that a==3 and b==2 after applying the swap function in
each
case, Explain your answer.

Q4 Write a program to count the number of vowels in the following array of pointers to
strings:

char * str[ ] = {
Friends is an American television sitcom,
created by David Crane and Marta Kauffman
which originally aired on NBC
}

Q5

#include<stdio.h>
char *c[]={"ENTNG","NST","AMAZI","FIRBE"};
char **cp[]={c+3,c+2,c+1,c};
char ***cpp=cp;
void main()
{
printf("%s",**++cpp);
printf("%s",*((*++cpp)-1)+3);
printf("%s",*cpp[-2]+3);
printf("%s",cpp[-1][-1]+1);}

Explain the output


Q6 Write a program to sort the following array of pointers

char * str[ ] = {
american
created
which
david
bestow
}
Q7 Write a program to reverse a line using pointers
Q8 Write the function

replace(char string[], char from[], char to[])

which finds the string from in the string string and replaces it with the string to. You may
assume that from and to are the same length. For example, the code

char string[] = "recieve";


replace(string, "ie", "ei");
should change string to "receive".

(Extra credit: Think about what replace() should do if the from string appears multiple
times in the input string.)

Q9 Write a program to reverse the words in a sentence in place

That is, given a sentence like this


I am a good boy
The in place reverse would be
boy good a am I

Das könnte Ihnen auch gefallen