Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- find the size of a char array in two ways
- */
- #include <stdio.h>
- unsigned int strsize(char* str) {
- unsigned int s = sizeof(str) / sizeof(str[0]);
- return s;
- }
- int main(void) {
- char str [5] = "abcde";
- // inline
- int size1 = sizeof(str) / sizeof(str[0]);
- // function call
- int size2 = strsize(str);
- printf("* size: expected %d\n", 5);
- printf(" inline) %d\n", size1);
- printf(" function call) %d\n", size2);
- return 0;
- }
- // compile>>> gcc -o strsize.out strsize.c
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement