Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Simple C Code,

Posted on 2004-08-26
6
Medium Priority
?
293 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

705 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