The presented program shall not compile at least because there are used several undeclared names.
How can I make this code work. Address in main is different inside
func as well as the value is not the sam ?
It seems you are trying to achieve something like the following
#include <stdio.h>
const char *Like = "CO";
void func( const char *chP );
int main(void)
{
printf( "%p\n", ( void * )Like );
printf( "%c\n", Like[0] );
func( Like );
}
void func( const char *chP )
{
printf( "%p\n", ( void * )chP );
printf( "%c\n", chP[0] );
}
The program output might look like
0x555a23f0d004
C
0x555a23f0d004
C
As you can see the outputted addresses and values in main
and in the function func
are the same.
Pay attention to that to output a value of a pointer you should use the conversion specifier p
.
And according to the C Standard the function main without parameters shall be declared like
int main( void )