i have this piece of code
int main()
{
char a[100];
a[0]='a';
a[1]='b';
fun(a[0]);
}
void fun(char *a)
{
printf("%c",a);
}
but im passing a character to a pointer.will the pointer not be expecting an address???
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
a[0]holds the value97('a'in ASCII).funwill receive the value97inabut interpret it as an address. However, since you’re only passing it toprintf, and happen to incorrectly be using the%cformatter which will interpretaas achar, you’ll end up printingaanyway.Of course, on most compilers you should receive warnings that:
fun) without casting it to a pointer.%cformatter inprintfshould take achar, not achar *.