Please enable JavaScript.
Coggle requires JavaScript to display documents.
Tokens of C Programming, Strings, Identifiers, Constants, Keywords,…
Tokens of C Programming
Strings
Definition
A string is a data type that consists of alphanumeric characters (letters and numbers).
Characteristics
Enclosed in double quotes " "
Stored as an array of characters
Declaration
char str[] = "Hello";
char *str = "World";
Functions from <string.h>
strlen(str)
— length
strcpy(dest, src)
— copy
strcat(dest, src)
— concatenate
strcmp(str1, str2)
— compare
strchr(str, ch)
— locate char
strstr(haystack, needle)
— locate substring
Escape Sequences
\n
- New line
\t
- Horizontal tab
\
- Backslash
\'
- Single quote
\"
- Double quote
\r
- Carriage return (moves cursor to start of line)
\b
- Backspace (deletes previous character)
\f
Form feed (page break in printers)
\v
- Vertical tab
\a
- Alert (bell sound or beep)
\0
- Null character (marks end of string)
Identifiers
Definition
An identifier is a name used to uniquely identify a variable, function, class, or other programming element.
Difference between
Identifiers and Variables
Scope
Identifiers are general names for identifying specific elements
Variables are names for data storage elements
All Identifiers are Variables
Not all Variables are Identifiers
Rules for Naming
Cannot start with digits
No special characters
Cannot be a keyword
Best Practices
Use camelCase or snake_case
Use meaningful names
Constants
Definition
A constant is a value that is not altered by the program during normal execution.
Classification
Integer Constants
Floating Point Constants
Character
Constants
String
Constants
Enumeration
Constants
Ways to Define
Using #define
Syntax:
#define PI 3.14159
Replaces all instances before compilation
No type checking
Using const Keyword
Syntax:
const int MAX = 100;
Type-safe and scoped like variables
Can be pointers, strings, etc.
Rules
Must be assigned at initialization
Cannot be modified later
Follow naming rules for identifiers
Keywords
Definition
A set of predefined words used by the compiler which cannot be used as variables or identifiers. There are 32 such words.
Classification
Data Types
int, float, char, double, void, etc.
Control Statements
if, else, switch, case, default
Loops
for, while, do
Storage Class Specifiers
auto, register, static, extern
Access Modifiers
const, volatile
Return Statement
Others
break, continue, sizeof, typedef, enum, goto, struct, union, etc.
Operators
Definition
Operators are special symbols that tell the compiler to perform specific mathematical or logical operations on values or variables
Classification
Arithmetic
+, -, *, /, %
Relational
==, !=, <, >, <=, >=
Logical
&&, ||, !
Assignment
=, +=, -=, etc.
Increment/Decrement
++, --
Bitwise
&, |, ^, ~, <<, >>
Ternary
? :
Special Symbols
Definition
Special symbols are characters that have specific meanings and functions beyond representing letters or numbers. They are used to structure code, define operations, and control the program's flow.
Classification
Brackets
[],{},()
[]
— array subscripting
{}
— block of code
()
— function calls or precedence
Punctuation
; , . ->
;
— statement terminator
,
— separator
.
— structure member access
->
— pointer to structure member
Operators
*&
Escape Sequences
\n, \t, \, \"
Pre-processor
'#' for #include, #define