Skip to content

Commit

Permalink
Completed page 53 exercise on how to pass a string to a function. Thi…
Browse files Browse the repository at this point in the history
…s also addressed why the sizeof returns a length shorter than the actual string, as this variable is a pointer to a char.
  • Loading branch information
terryjbates committed Feb 13, 2013
1 parent bed58e2 commit 0134afe
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions chapter-2-memory-and-pointers/fortune_cookie.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>

void fortune_cookie(char msg[])
{
printf("Message reads: %s\n", msg);
printf("Message reads: %p\n", msg);
printf("msg occupies %lu bytes\n", sizeof(msg));
}

int main(){
char quote[] = "Cookies make you fat";
fortune_cookie(quote);
return 0;
}

0 comments on commit 0134afe

Please sign in to comment.