Podcast
Questions and Answers
Consider a scenario where you need to dynamically allocate memory for an array of integers in C. Which of the following functions is most appropriate for this task, and how should it be used?
Consider a scenario where you need to dynamically allocate memory for an array of integers in C. Which of the following functions is most appropriate for this task, and how should it be used?
- `alloc(n, int)` to allocate memory, and `release()` to release the memory.
- `calloc(n, sizeof(int))` to allocate and initialize memory, and `dealloc()` to release the memory.
- `malloc(n * sizeof(int))` to allocate memory, and `free()` to release the memory. (correct)
- `realloc(ptr, n * sizeof(int))` to reallocate memory, and `clear()` to release the memory.
What is the significance of the static
keyword when used with a variable inside a function in C?
What is the significance of the static
keyword when used with a variable inside a function in C?
- The variable is visible only within the file it is defined in.
- The variable's value is stored in a register for faster access.
- The variable's lifetime extends across multiple function calls, retaining its value between calls. (correct)
- The variable is automatically deallocated when the function returns.
In C programming, what is the difference between const int *ptr
and int * const ptr
?
In C programming, what is the difference between const int *ptr
and int * const ptr
?
- `const int *ptr` makes the pointer constant, while `int * const ptr` makes the integer constant.
- `const int *ptr` allows modification of the integer but not the pointer, while `int * const ptr` allows modification of the pointer but not the integer.
- `const int *ptr` makes the integer constant, while `int * const ptr` makes the pointer constant. (correct)
- There is no difference; both declarations are interchangeable.
In C, how does passing an array to a function differ from passing an integer?
In C, how does passing an array to a function differ from passing an integer?
What is the primary purpose of using function pointers in C programming?
What is the primary purpose of using function pointers in C programming?
Which of the following statements best describes the difference between a structure and a union in C?
Which of the following statements best describes the difference between a structure and a union in C?
What is the significance of using volatile
keyword in C?
What is the significance of using volatile
keyword in C?
What is the behavior of the following C code snippet if an error occurs during the file writing operation using fwrite
?
size_t bytes_written = fwrite(data, size, count, file_ptr);
What is the behavior of the following C code snippet if an error occurs during the file writing operation using fwrite
?
size_t bytes_written = fwrite(data, size, count, file_ptr);
Consider a scenario where you need to handle different data types using a generic pointer in C. What is the correct way to access the value pointed to by a void *
pointer?
Consider a scenario where you need to handle different data types using a generic pointer in C. What is the correct way to access the value pointed to by a void *
pointer?
What is the potential issue with the following C code snippet designed to copy a string, and how can it be resolved?
char *dest = malloc(strlen(src));
strcpy(dest, src);
What is the potential issue with the following C code snippet designed to copy a string, and how can it be resolved?
char *dest = malloc(strlen(src));
strcpy(dest, src);
Flashcards
What is a Pointer?
What is a Pointer?
A symbolic representation of a memory location. Holds addresses of other variables.
What are Arrays?
What are Arrays?
Contiguous memory locations holding data of the same type.
What is a Function?
What is a Function?
Self-contained block of code that performs a specific task. Can accept parameters and return a value.
What are Loops?
What are Loops?
Signup and view all the flashcards
Memory management
Memory management
Signup and view all the flashcards
Study Notes
- A question series focusing on C Programming is presented for BARC 2025 (Bhabha Atomic Research Centre) aspirants.
- The session covers questions regarding pointers, arrays, functions, loops and memory management.
- Problems discussed include conceptual and coding-based questions.
- The aim is to boost confidence for BARC and other competitive exams through understanding key programming logic and sharpening problem-solving skills.
- Class notes can be found at a provided link.
- Links to PW App/Website and PW Store are also provided.
- GATE (Graduate Aptitude Test in Engineering) batches and rank improvement batches for 2026 and 2027 are mentioned, with links for various engineering disciplines
- Several Telegram groups and social media pages for GATE Wallah and Physics Wallah are listed.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.