Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Home » Tip Bank » C++
Language: C++
Expertise: Beginner
Oct 20, 1998



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Visual C++ 5.0 compatible with C?

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.
void sort (int a[], int n)
	int i, j, temp;

	for (i = 0; i < n-1; ++i)
		for (j = i + 1; j < n; ++j)
			if (a[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:\n");
	for ( i = 0; i < 16; ++i)
	printf ("%i ", array[i]);

	sort (array, 16);

	printf ("\n\nThe array after the sort:\n");
	for ( i = 0; i < 16; ++i)
		printf ("%i ", array[i]);
	printf ("\n");

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 Pro
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date