Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

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
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.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top