In this eg,using call by address concept in order to retrieve all the data changes which is happening in the function call...
In main()
,
i)passing two arguments i)int pointer ii)pointer to constant -> which cannot change the value it is holding...
ii)Changing the values of int * and assigning some values to const void * in the function calls.
*Finally i'm trying to print the values in main()
*getting the int pointer values properly(no issues)
*getting the void pointer value as NULL..
Requirement:
Need to get the output in main()
like this
main::ajskdffllagkdjdjdhdjhd(i mean to say that i need to print the void * values like this)
But i'm getting the value as main:: NULL
What shall i need to do inorder to get the expected output?
#include <stdio.h>
#include <stdlib.h>
void func(int *len,const void *pBuf);
void func2(int **len,const void **pBuf);
void func3(int ***len,const void ***pBuf);
int main()
{
int len = 0;
const void *pBuf;
printf("len b4 ::%d\n",len);
printf("%p\n",&pBuf);
func(&len,&pBuf);
printf("len after::%d\n",len);
printf("%p\n",&pBuf);
printf("main::%s\n",(const char *)pBuf);
return 0;
}
void func(int *len,const void *pBuf)
{
*len = 20;
printf("func1 :: %p\n",&pBuf);
func2(&len,&pBuf);
}
void func2(int **len,const void **pBuf)
{
printf("func2::%p\n",&pBuf);
**len = 30;
func3(&len,&pBuf);
}
void func3(int ***len,const void ***pBuf)
{
const void *pMy = "ajskdffllagkdjdjdhdjhd";
**pBuf = pMy;
printf("func3::%p\n",&pBuf);
printf("func3::%s\n",(const char *)**pBuf);
***len = 40;
}
Output:
len b4::0
0x7fffa9c51468
func1 :: 0x7fffa9c51440
func2::0x7fffa9c51420
func3::0x7fffa9c513f0
func3::ajskdffllagkdjdjdhdjhd
len after::40
0x7fffa9c51468
main::(null)