Value gets changed when passed to a function in C++
Why do I see different values of character 'a', in main() and in functionA() in the following C++ code?
Code:
#include <stdio.h> Code:
anisha@linux-uitj:~> g++ qqqqq.cpp -Wall -Wextra |
Hi
You define "byte" like as a pointer to unsigned char. The paramter you send to functionA is "(unsigned char*)&byte" which means the address of the pointer typecasted to an unsigned char pointer. I guess you intend to pass the pointer to the function, not a pointer to the pointer. |
It's because a is a char and byte is an unsigned char. Different interpretation.
|
Quote:
I modified the code as follows and it worked. Code:
functionA ((unsigned char*)byte); |
Quote:
Thanks for bothering :) |
I was too fast to respond. that was not the problems.
You could just make the call even simply: functionA(byte); |
Quote:
Quote:
|
LOL the other thread I was responding to the wrong information, to another poster and not the values in the original question.
So i just wanted to delete to whole post but i guess i should have made an edit note. |
All times are GMT -5. The time now is 02:43 PM. |