Solved

Simple C Code,

Posted on 2004-08-26
6
285 Views
Last Modified: 2010-04-15
hi experts,

I wrote a code in C as shown below and its giving the following error.
Cannot convert int* to int
Type mismatch in parameter1 in call to Junk(int,int)
Cannot convert int* to int
Type mismatch in parameter2 in call to Junk(int,int)

could anyone explain to me why this error? pls explain in a simple way, newbie here>)
#include<stdio.h>
#include<conio.h>
void junk(int,int);
void main()
{
int i=5,j=2;
junk(&i,&j);
printf ("\n%d%d",i,j);
}
void junk(int *i,int *j)
{

*i=*i**i;
*j=*j**j;
}
really appreciate the help
thanks in advance
deep
0
Comment
Question by:deepthiji
  • 4
  • 2
6 Comments
 
LVL 11

Expert Comment

by:avizit
ID: 11908745
in your functrion prototype you have


void junk(int,int);

while for your function definition you have


void junk(int *i,int *j)
{

*i=*i**i;
*j=*j**j;
}


so t hey dont match



0
 
LVL 11

Expert Comment

by:avizit
ID: 11908749
so you can just change the funtion prototype

from

void junk(int,int);

to

void junk(int *,int *);



0
 
LVL 3

Author Comment

by:deepthiji
ID: 11908761
sorrry i did not get that, As i said i just started learnning C,
>>in your functrion prototype you have
>>void junk(int,int);

>>while for your function definition you have
>>void junk(int *i,int *j)

what is wrong, should i declare void junk(int*,int*) at the bginning?
please explain some more,


0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 11

Expert Comment

by:avizit
ID: 11908790
right ..


in the third line of your code it is the function prototype , here you tell the compiler what yuor function looks like i.,e what is its return type and what are its arguments

so you declare the function as

void junk(int,int);   i.e you say that the function named 'junk' retunrs no value and takes two integers as arguments.

but when you actuallky define the function you are defining it as

void junk(int *i,int *j)
{

*i=*i**i;
*j=*j**j;
}

i.e here you say that the function  returns  no value ( i.e void) and takes two pointer to integers (int *i, int *j)   as arguments

so you see your declaration and definition has a mismatch

thats why the error


>>>>
Cannot convert int* to int
Type mismatch in parameter1 in call to Junk(int,int)
Cannot convert int* to int
Type mismatch in parameter2 in call to Junk(int,int)
<<<<<


hence to correct it you should change the prototype to match the fucntion definition
so yuo can chnage the third line of your program

from

void junk(int,int);

to

void junk(int *,int *);




0
 
LVL 11

Accepted Solution

by:
avizit earned 500 total points
ID: 11908810
also your expressions look messy ,
it is advisable to use brackets  to make the meaning more clear

change

*i=*i**i;
*j=*j**j;

to

*i  =  (*i)  *  (*i);
*j  =  (*j)  *  (*j);

This way its more readable and easier to get the meaning at a glance
0
 
LVL 3

Author Comment

by:deepthiji
ID: 11908816
Got it, thanks a loot for the help,
thanks once again.
0

Featured Post

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question