#include
int main() {
char c = 'A';
printf("%d", c);
return 0;
}
The %d format specifier prints the ASCII value of the character. 'A' has ASCII value 65.
#include
int main() {
char str[] = "Hello";
printf("%c", str[1]);
return 0;
}
String indexing starts at 0. str[0] = 'H', str[1] = 'e'.
A pointer stores the memory address of a variable. Pointer size depends on the system architecture, not always 4 bytes.
#include
int main() {
int arr[] = {10, 20, 30};
printf("%d", *(arr + 1));
return 0;
}
arr + 1 points to the second element. Dereferencing with * gives the value 20.
The 'const' keyword creates a constant variable that cannot be modified after initialization. The compiler enforces this at compile time.
Variable names must start with a letter or underscore, not a digit. They cannot contain hyphens or spaces. _var123 is the only valid name.
\t is the escape sequence for a tab character. \n is for newline, \s is invalid in C.
The main() function is the entry point where program execution begins. Every C program must have a main() function.
Following operator precedence, multiplication (*) has higher precedence than addition (+). So 3*2=6, then 5+6=11.
#include
int main() {
int x = 5;
printf("%d", x++);
return 0;
}
x++ is post-increment. The value 5 is printed first, then x is incremented to 6.