Click here to Skip to main content
15,891,027 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C++
<pre>#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int test (char *param) {
    printf("%d", *param);
}
int main(void){
    char a[]="9009";
    test(a);
}


What I have tried:

I tried many experiments on this code. Still, I don't know why *param is printing 57?
Posted
Updated 7-Mar-22 0:09am
v2
Comments
Richard MacCutchan 7-Mar-22 5:33am    
Because that is what you told it to print. If you want the first character of the string then use the %c format type.
_Asif_ 7-Mar-22 6:10am    
what do you think it should print?

Quote:
I tried many experiments on this code. Still, I don't know why *param is printing 57?

57 is the ascii code for "9"
ASCII - Wikipedia[^]
 
Share this answer
 
You should have written instead
C
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void test (const char * param)
{
    printf("%s\n", param);
}
int main(void)
{
    char a[] = "9009";
    test(a);
    return 0;
}

See printf - C++ Reference[^].
 
Share this answer
 
Comments
Patrice T 7-Mar-22 7:54am    
+5
CPallini 7-Mar-22 8:38am    
Thank you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900