C Programming for BARC 2025

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson
Download our mobile app to listen on the go
Get App

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?

  • `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?

  • 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?

  • `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?

<p>Arrays decay into pointers to their first element when passed to a function, while integers are passed by value. (B)</p>
Signup and view all the answers

What is the primary purpose of using function pointers in C programming?

<p>To pass a function as an argument to another function, enabling dynamic behavior and callbacks. (C)</p>
Signup and view all the answers

Which of the following statements best describes the difference between a structure and a union in C?

<p>A structure allocates memory for all its members, while a union allocates memory only for the largest member. (A)</p>
Signup and view all the answers

What is the significance of using volatile keyword in C?

<p>It informs the compiler that a variable's value may be changed by external factors, preventing certain optimizations. (B)</p>
Signup and view all the answers

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);

<p><code>fwrite</code> will return the number of elements successfully written, which may be less than <code>count</code> if an error occurred. (A)</p>
Signup and view all the answers

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?

<p>Cast the <code>void *</code> pointer to the appropriate data type before dereferencing. (D)</p>
Signup and view all the answers

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);

<p>The code might cause a buffer overflow because <code>malloc</code> does not allocate space for the null terminator. Allocate <code>strlen(src) + 1</code> bytes instead. (A)</p>
Signup and view all the answers

Flashcards

What is a Pointer?

A symbolic representation of a memory location. Holds addresses of other variables.

What are Arrays?

Contiguous memory locations holding data of the same type.

What is a Function?

Self-contained block of code that performs a specific task. Can accept parameters and return a value.

What are Loops?

Control flow statements that repeat a block of code until a condition is met.

Signup and view all the flashcards

Memory management

The process of allocating and deallocating memory during the execution of a program.

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.

Quiz Team

More Like This

C Programming
3 questions

C Programming

UnquestionableMoldavite1696 avatar
UnquestionableMoldavite1696
Use Quizgecko on...
Browser
Browser