FlashKeepers

C and C++ · College · College and University

C II: Pointers and Dynamic Memory

Pointer declaration and arithmetic, malloc, calloc, realloc, free, function pointers, memory leaks and dangling pointers.

About this set

40 basic cards for College C and C++. It opens with "How do you declare a pointer to an integer in C?" and "What does the & (address-of) operator return?". Study it alongside the other College sets below.

40 cards · basic cards · AI-written, checked twice. Edit anything.

Study this set free Look inside first Get FlashKeepers for iPhone

Opens in your browser, no account. Get the iPhone and iPad app · Android app

How do you declare a pointer to an integer in C?
Show answerint *ptr; or int* ptr;
What does the & (address-of) operator return?
Show answerThe memory address of a variable
What does the * (dereference) operator do?
Show answerAccesses the value stored at the address the pointer points to
What is the purpose of a void pointer?
Show answerA generic pointer that can point to any data type
If ptr points to an int and you execute ptr++, how many bytes does the address increase by?
Show answerThe size of an int, typically 4 bytes on most systems
What is the result of subtracting one pointer from another?
Show answerThe number of elements between them in memory
What is the difference between ptr++ and ++ptr when advancing a pointer in a loop?
Show answerPost-increment returns the old value, pre-increment returns the new value, but both advance the pointer the same amount
What value does a NULL pointer represent?
Show answerAn uninitialized or invalid address, typically defined as 0 or 0x0
What does malloc stand for?
Show answerMemory allocation
What does malloc return if it fails to allocate memory?
Show answerNULL (a null pointer)
Which header file contains malloc?
Show answerstdlib.h
Does malloc initialize allocated memory to any specific value?
Show answerNo, the memory contains garbage values
What is the correct syntax to allocate an array of 10 integers using malloc?
Show answerint *arr = (int*)malloc(10 * sizeof(int));
What are the two parameters of the calloc function?
Show answerThe number of elements and the size of each element in bytes
What is the main advantage of calloc over malloc?
Show answercalloc initializes all allocated memory to zero

25 more cards in the app

Study this set free