Problem with Reference

Write here if you have problems with your C source code

Moderator: Board moderators

Post Reply
kaushik_acharya
New poster
Posts: 17
Joined: Thu Jul 28, 2005 3:05 pm
Location: Bangalore, India

Problem with Reference

Post by kaushik_acharya »

I am getting compile error... Why is it giving error?

Code: Select all

#include <stdio.h>
#include <stdlib.h>

// void increment_func(int&);

void increment_func(int& x)
{
	x++;
	// return;
}

void incr_func(int* x)
{
	(*x)++;
}

void main()
{
	int int1;

    printf ("integer 1:");
    scanf("%d",&int1);

	increment_func(int1);
    printf ("integer 1: %d",int1);

	incr_func(&int1);
	printf ("integer 1: %d",int1);

    return;
}
mpi
New poster
Posts: 46
Joined: Fri Nov 03, 2006 7:53 pm
Location: Madrid

Post by mpi »

ANSI C doesn't allow to define the main function with other return type different from int. By the way, if that is C code, you can't use references (increment_func). These are only available in C++ language. Submit your code choosing the C++ compiler.

To prevent such compiling errors on the online judge, use the same compiling options given on the submit page:

Code: Select all

g++ -lm -lcrypt -O2 -pipe -ansi
Actually, just -ansi will suffice.
Post Reply

Return to “C”