devxlogo

Visual C++ 5.0 compatible with C?

Visual C++ 5.0 compatible with C?

Question:
I am studying C and C++ programming on my own. I have no previous programming experience. I am using Visual C++ 5.0 to run the following example “program 8.12” written in the book Programming in ANSI C, revised edition by S. G. Kochan. But Visual C++ 5.0 would not even compile it. Is this the backward compatibility problem of Visual C++ 5.0? There are 24 errors. The error started from “int i;” in the beginning of main(), it read “C2235 ‘;’ in formal parameter list.

// Program 8.12// Sort an array of intergers into ascending order.#include void sort (int a[], int n){	int i, j, temp;	for (i = 0; i  a[j])			{				temp = a[i];				a[i] = a[j];				a[j] = temp;			}}void main ()( 	int i;	int array[16] = {34, -5, 6, 0, 12, 100, 56, 22, 44, -3, -9, 12, 17, 22, 6, 11};		void sort (int a[], int n);	printf ("The array before the sort:
");			for ( i = 0; i 

Answer:
Visual C++ 5.0 is indeed compatible with C and the code you posted looks pretty clean. There was just one problem: the line following void main () has an open parenthasis ("(") instead of an open curly brace ("{"). I changed it to a curly brace and it compiled just fine.

devx-admin

Share the Post: