Skip to content

Instantly share code, notes, and snippets.

@ninjatrench
Created January 29, 2015 16:32
Show Gist options
  • Save ninjatrench/ee3643a53db4fb7ce7d1 to your computer and use it in GitHub Desktop.
Save ninjatrench/ee3643a53db4fb7ce7d1 to your computer and use it in GitHub Desktop.
strlen vs sizeof
#include<stdio.h>
#include<string.h>
void main(){
const char str[] = "Heya Buddy";
printf("sizeof(%s): %zu\n", str ,sizeof(str));
printf("strlen(%s): %zu\n", str, strlen(str));
const char* str2 = "Heya Buddy";
printf("\n");
printf("sizeof(%s): %zu\n", str2, sizeof(str2));
printf("strlen(%s): %zu\n", str2, strlen(str2));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment