C examples for Pointer:Introduction
Declares and initializes an array of character pointers and then asks for ratings associated
#include <stdio.h> int main()/* w ww . j a v a2 s . c o m*/ { char ans; char * movies[9] = {"A", "B", "C", "D", "E", "F", "G", "S", "Z"}; int movieratings[9]; // A corresponding array of 9 integers for movie ratings char * tempmovie = "This will be used to sort rated movies"; int didSwap, temprating; // for the sort loop for (int i=0; i< 9; i++) { printf("", movies[i]); printf("\nWhat was your rating on a scale "); printf("of 1-10: "); scanf(" %d", &movieratings[i]); } for (int outer = 0; outer < 8; outer++) { didSwap = 0; for (int inner = outer; inner < 9; inner++) { if (movieratings[inner] > movieratings[outer]) { tempmovie = movies[inner]; temprating = movieratings[inner]; movies[inner] = movies[outer]; movieratings[inner] = movieratings[outer]; movies[outer] = tempmovie; movieratings[outer] = temprating; didSwap = 1; } } if (didSwap == 0) { break; } } for (int i=0; i < 9; i++) { printf("%s rated a %d!\n", movies[i], movieratings[i]); } return(0); }