Skip to content

C Programming

Master C Programming with 50 free flashcards. Study using spaced repetition and focus mode for effective learning in Programming.

🎓 50 cards ⏱️ ~25 min Advanced
Study Full Deck →
Share: 𝕏 Twitter LinkedIn WhatsApp

🎯 What You'll Learn

Preview Questions

12 shown

What is a pointer in C?

Show ▼

A pointer is a variable that stores the memory address of another variable.
Declared using the * operator: int *ptr;
The address-of operator & retrieves a variable's address: ptr = &x;

How do you dereference a pointer?

Show ▼

Dereferencing means accessing the value stored at the address a pointer holds.
Use the * operator: int val = *ptr;
This retrieves the value at the memory location pointed to by ptr.

What is a NULL pointer?

Show ▼

A NULL pointer is a pointer that does not point to any valid memory location.
Assigned with: int *ptr = NULL;
Always check for NULL before dereferencing to avoid segmentation faults.

What does malloc() do in C?

Show ▼

malloc() allocates a block of memory on the heap and returns a pointer to it.
Syntax: int *p = (int *)malloc(n * sizeof(int));
Returns NULL if allocation fails. Memory is uninitialized.

What is the difference between malloc() and calloc()?

Show ▼

malloc(size) allocates uninitialized memory of the given sizecalloc(count, size) allocates memory for an array of count elements, each of size bytes, and initializes all bits to zero

Why must you call free() after malloc()?

Show ▼

Calling free(ptr) releases dynamically allocated memory back to the system.
Failing to free causes a memory leak, where allocated memory is never reclaimed.
After freeing, set the pointer to NULL to avoid dangling pointer issues.

What is a dangling pointer?

Show ▼

A dangling pointer points to memory that has been freed or deallocated.
Dereferencing it causes undefined behavior.
Prevention: set pointers to NULL after calling free().

What is a struct in C?

Show ▼

A struct (structure) groups related variables of different types under one name.
Example:
struct Point { int x; int y; };
Access members with the dot operator: p.x or arrow operator for pointers: ptr->x

How do you dynamically allocate a struct?

Show ▼

Use malloc() with sizeof:
struct Point *p = (struct Point *)malloc(sizeof(struct Point));
Access members via the arrow operator: p->x = 10;
Remember to free(p) when done.

What is a union in C?

Show ▼

A union is like a struct, but all members share the same memory location.
The size of a union equals the size of its largest member.
union Data { int i; float f; char c; };
Only one member can hold a value at a time.

What is the difference between a struct and a union?

Show ▼

Struct: each member has its own memory; size is the sum of all members (plus padding)Union: all members share the same memory; size equals the largest memberStructs store multiple values simultaneously; unions store only one at a time.

What is an enum in C?

Show ▼

An enum (enumeration) defines a set of named integer constants.
enum Color { RED, GREEN, BLUE };
By default, values start at 0 and increment by 1.
You can assign custom values: enum Color { RED = 1, GREEN = 5 };

🎓 Start studying C Programming

🎮 Study Modes Available

🔄

Flashcards

Flip to reveal

🧠

Focus Mode

Spaced repetition

Multiple Choice

Test your knowledge

⌨️

Type Answer

Active recall

📚

Learn Mode

Multi-round mastery

🎯

Match Game

Memory challenge

Related Topics in Programming

📖 Learning Resources