What is the correct output of sizeof(“string”)?

This is all 100% standardized. C17 6.10.8.1: __DATE__ The date of translation of the preprocessing translation unit: a character string literal of the form “Mmm dd yyyy” … and the first character of dd is a space character if the value is less than 10. … __TIME__ The time of translation of the preprocessing translation … Read more

How do I find the size of a struct? [closed]

#include <stdio.h> typedef struct { char* c; char b; } a; int main() { printf(“sizeof(a) == %d”, sizeof(a)); } I get “sizeof(a) == 8”, on a 32-bit machine. The total size of the structure will depend on the packing: In my case, the default packing is 4, so ‘c’ takes 4 bytes, ‘b’ takes one … Read more

Element count of an array in C++

Let’s say I have an array arr. When would the following not give the number of elements of the array: sizeof(arr) / sizeof(arr[0])? One thing I’ve often seen new programmers doing this: void f(Sample *arr) { int count = sizeof(arr)/sizeof(arr[0]); //what would be count? 10? } Sample arr[10]; f(arr); So new programmers think the value … Read more

Printing a char with printf

%d prints an integer: it will print the ascii representation of your character. What you need is %c: printf(“%c”, ch); printf(“%d”, ‘\0’); prints the ascii representation of ‘\0’, which is 0 (by escaping 0 you tell the compiler to use the ascii value 0. printf(“%d”, sizeof(‘\n’)); prints 4 because a character literal is an int, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)