munmap_chunk(): invalid pointer

In the function second(), the assignment word = “ab”; assigns a new pointer to word, overwriting the pointer obtained through malloc(). When you call free() on the pointer later on, the program crashes because you pass a pointer to free() that has not been obtained through malloc(). Assigning string literals does not have the effect of copying their content as you might have thought. To … Read more

Categories C Tags

Error “initializer element is not constant” when trying to initialize variable with const

In C language, objects with static storage duration have to be initialized with constant expressions, or with aggregate initializers containing constant expressions. A “large” object is never a constant expression in C, even if the object is declared as const. Moreover, in C language, the term “constant” refers to literal constants (like 1, ‘a’, 0xFF and so on), enum members, and results of … Read more

What does #pragma once mean in C? [duplicate]

In the C and C++ programming languages, #pragma once is a non-standard but widely supported preprocessor directive designed to cause the current source file to be included only once in a single compilation. Thus, #pragma once serves the same purpose as #include guards, but with several advantages, including: less code, avoiding name clashes, and improved … Read more

The importance of c enumeration (typedef enum) [duplicate]

I recently saw this in an answer that was posted for me: What is typedef enum and why should we use it? I googled and found the following: http://www.programiz.com/c-programming/c-enumeration Right now it sounds slightly too technical for me so I dont think I understand what is going on or why one would use that. Bonus (optional): … Read more

Categories C Tags

printf() formatting for hexadecimal

Why, when printing a number in hexadecimal as an 8 digit number with leading zeros, does %#08X not display the same result as 0x%08X? When I try to use the former, the 08 formatting flag is removed, and it doesn’t work with just 8.

munmap_chunk(): invalid pointer

In the function second(), the assignment word = “ab”; assigns a new pointer to word, overwriting the pointer obtained through malloc(). When you call free() on the pointer later on, the program crashes because you pass a pointer to free() that has not been obtained through malloc(). Assigning string literals does not have the effect of copying their content as you might have thought. To … Read more

Categories C Tags

“error: assignment to expression with array type error” when I assign a struct field (C)

You are facing issue in because, in the LHS, you’re using an array type, which is not assignable. To elaborate, from C11, chapter §6.5.16 assignment operator shall have a modifiable lvalue as its left operand. and, regarding the modifiable lvalue, from chapter §6.3.2.1 A modifiable lvalue is an lvalue that does not have array type, […] You need to use strcpy() to copy … Read more

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