0

while compiling error says insert ')'at void swap(&a,&b); I can't understand this error here is the code

#include <stdio.h>
#include <cs50.h>
void swap (int* x,int* y);
int main (void)
{
    printf("Enetr first int\n");
    int a = GetInt();
    printf("Enetr second int int\n");
    int b = GetInt();
    printf ("Swapped values\n");
    void swap(&a,&b);
    printf ("%i\n", a);
    printf("%i\n", b);
    return 0;
}

void swap (int* a,int* b)
{
    int temp = *a;
    *a = *b;
    *b = temp;
}

don't know why code is not having proper format although I am trying to do it.

2

You don't need to specify the return type of your function when you call it, only when you declare/define it.

So you've declared the function right, like this: void swap (int* a,int* b)

But when you call it, you have to omit the type specifications, like this: swap(&a,&b);

But what you've done is this: void swap(&a,&b);

TL;DR: remove the word void before swap(&a,&b);

| improve this answer | |
  • Thanks for the answer it's working now – Ahmed Raza Nov 18 '16 at 7:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .