what is the bug of this code

Status
Not open for further replies.

AliBahar

Member level 2
Joined
Feb 4, 2015
Messages
42
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Visit site
Activity points
337
Hi
when I compiled this code in visual studio the num1 equals with 4.
and if I changed the size of data array the previous value is appeared and it is not changed.
Code:
#include "stdio.h"
char data[]={0x11, 0x12, 0x14, 0x12};

char sizeCount(char *ptr){	
	static char num;
	num=sizeof(ptr);
	return num;
}
int main(void){
	char num1;
	num1=sizeCount(data);
	printf("%d", num1);
	getchar();
	return 0;
}
 

sizeof() is returning the size of the pointer, which is 32 bit. There's no way to find the size of the referenced data object from a pointer.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…