Skip to main content

Featured

C Pattern Programs: Square Number and Alphabet Patterns Explained

๐Ÿ”ท Square Star Pattern ๐Ÿ“‹ Copy Code #include <stdio.h> int main() { int num; printf("Enter the number:\n"); scanf("%d", &num); for(int i = 1; i <= num; i++) { for(int j = 1; j <= num; j++) { printf("* ");//keep"* " } printf("\n"); } return 0; } ๐Ÿ”ท Reverse Square Alphabet Pattern (Column-wise) ๐Ÿ“‹ Copy Code #include <stdio.h> int main() { int num; printf("Enter the number:\n"); scanf("%d", &num); for(int i = num; i >= 1; i--) { for(int j = num; j >= 1; j--) { printf("%c ", j + 64);//%c for Character and 64 will be ASIIC VALUE } printf("\n"); } return 0; } ๐Ÿ”ท Reverse Square Alphabet Pattern (Row-wise) ๐Ÿ“‹ Copy Code #include <stdio.h> int main() { int num; ...

Top 5 Examples of volatile in C

Top 5 Examples of volatile in C

// Example 1: GPIO Register
#define GPIO_PORT (*(volatile unsigned int*)0x40021000)
while ((GPIO_PORT & 0x01) == 0) { }

// Example 2: Interrupt Flag
volatile int interrupt_flag = 0;
void ISR() { interrupt_flag = 1; }

// Example 3: Watchdog Reset
volatile int system_reset = 0;
while (!system_reset) { }

// Example 4: Multi-thread Flag
volatile int data_ready = 0;
while (!data_ready) { }

// Example 5: Sensor Polling
#define SENSOR_STATUS_REG (*(volatile unsigned char*)0x40024000)
while ((SENSOR_STATUS_REG & 0x01) == 0) { }

Use volatile whenever a variable might change unexpectedly due to hardware, interrupts, or concurrency. This prevents compiler optimizations that can cause bugs in real-time systems.

Comments

Popular Posts

๐ŸŒ™