Thursday, September 30, 2010

Why C Arrays are not really pointers

Ok. This is to settle an argument regarding C, arrays and pointers. I know we were all taught to treat arrays like pointers and they do behave like pointers for the -MOST- part. Try this code for a little mind experiment. Don't cheat! Think about the answer first:


#include <stdio.h>

int main()
{
int len = 100;
char myarr[len];
char *ptr;
ptr = myarr;

printf( "sizeof(myarr) = %d\n", sizeof(myarr) );
printf( "sizeof(ptr) = %d\n", sizeof(ptr) );
return 0;
}


What will this little program print? ;)
Stay tuned for the answer!

Added 24 October 2010:
Oops. I've been so busy I fogot to post a follow up. Anyway, you can easily verify what the answer will be by compiling and running.

Monday, September 13, 2010

Little Tech Tips, now live from Tufts University!


Hello true believers.

Or at least those of you who happen to drop by from Google search. :)
Little Tech Tips has been on hiatus for several months because of a big change. I've gone back to school so we are now blogging all things little, tech and what not from the most excellent Tufts University.

As such, we will be covering new topics (which will most conveniently be related to whatever class I'm taking/TAing. ;)

Stay tuned!