• What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. The main reason for its popularity is because it is a fundamental language in the field of computer science.
C Programming
  • C Language Programming Syllabus
  • Course Overview
  • This comprehensive C Programming course is designed for computer students at your coaching institute, aiming to build a strong foundation in C language fundamentals and advanced programming concepts. Through a blend of theoretical lessons and hands-on practical exercises, students will develop the skills necessary to write efficient, reliable, and maintainable C programs. The course is structured into modules that progressively cover basic to advanced topics, ensuring a thorough understanding of the C programming language.
  • Learning Outcomes
  • By the end of this course, students will be able to:
  • Understand C Programming Basics: Grasp fundamental programming concepts and syntax of C.
  • Develop Structured Programs: Write structured and modular C programs using functions and control structures.
  • Manage Data Effectively: Utilize arrays, pointers, and structures for efficient data management.
  • Implement Advanced Programming Techniques: Employ dynamic memory allocation, file handling, and recursion.
  • Debug and Optimize Code: Identify and fix errors, and optimize code for better performance.
  • Apply Knowledge to Real-World Problems: Develop complete projects that solve practical problems using C.
  • Module-Wise Content
  • Module 1: Introduction to C Programming
  • Objective: To provide an overview of C programming, its history, features, and environment setup.
  • Topics:
  • Introduction to C:
    • History and evolution of the C language.
    • Importance and applications of C in software development.
  • C Language Features:
    • Advantages of using C.
    • Comparison with other programming languages.
  • Setting Up the Development Environment:
    • Installing and configuring IDEs (e.g., Code::Blocks, Dev-C++) and compilers (e.g., GCC).
    • Writing, compiling, and executing a simple C program.
  • Basic Structure of a C Program:
    • Components: Preprocessor directives, main() function, statements, and comments.
    • Understanding the compilation process.
  • Description: This module introduces students to the C programming language, highlighting its significance in the programming world. Students will set up their development environment and learn to write, compile, and execute their first C program. Understanding the basic structure of a C program lays the groundwork for more advanced topics.
  • Practical Exercises:
  • Install an IDE and set up a C programming environment.
  • Write and execute a simple “Hello, World!” program.
  • Modify the basic program to print different messages.
  • Module 2: Data Types, Variables, and Operators
  • Objective: To understand various data types, variable declarations, and the use of operators in C.
  • Topics:
  • Data Types:
    • Fundamental data types: int, char, float, double.
    • Derived data types: arrays, pointers, structures, unions.
    • Type qualifiers and modifiers.
  • Variables and Constants:
    • Variable declaration and scope.
    • Naming conventions and best practices.
    • Constants: #define vs. const keyword.
  • Operators in C:
    • Arithmetic operators (+, -, *, /, %).
    • Relational operators (==, !=, >, <, >=, <=).
    • Logical operators (&&, ||, !).
    • Bitwise operators (&, |, ^, ~, <<, >>).
    • Assignment operators (=, +=, -=, etc.).
    • Increment and decrement operators (++, --).
    • Ternary operator (?:).
  • Description: This module delves into the core building blocks of C programming—data types, variables, and operators. Students will learn how to declare variables, understand different data types, and utilize various operators to perform operations within their programs. Emphasis is placed on proper variable naming and scope management to write clear and maintainable code.
  • Practical Exercises:
  • Declare variables of different data types and initialize them.
  • Use arithmetic and logical operators in expressions.
  • Write programs that demonstrate operator precedence and associativity.
  • Implement constant variables and macros using #define.
  • Module 3: Control Structures
  • Objective: To master the use of control structures to dictate the flow of C programs.
  • Topics:
  • Decision-Making Statements:
    • if, if-else, nested if statements.
    • switch statements and use cases.
  • Looping Constructs:
    • for loops: Syntax and applications.
    • while loops: Syntax and use cases.
    • do-while loops: Syntax and differences from while.
  • Jump Statements:
    • break, continue, goto.
    • Use cases and best practices.
  • Nested Control Structures:
    • Combining loops and conditional statements.
    • Writing complex logical flows.
  • Description: Control structures are essential for managing the flow of execution in a program. This module covers various decision-making and looping constructs, enabling students to create programs that can make decisions and perform repetitive tasks efficiently. Understanding jump statements and nested structures further enhances their ability to control program flow.
  • Practical Exercises:
  • Implement programs using if-else and switch statements.
  • Create loops (for, while, do-while) to perform iterative tasks.
  • Use break and continue within loops to control execution.
  • Develop programs that combine multiple control structures for complex logic.
  • Module 4: Functions and Recursion
  • Objective: To understand the concept of functions, their implementation, and the use of recursion in C.
  • Topics:
  • Introduction to Functions:
    • Definition and importance of functions in modular programming.
    • Function declaration, definition, and invocation.
  • Function Types:
    • Standard library functions vs. user-defined functions.
    • Recursive functions and their applications.
  • Parameter Passing:
    • Pass by value vs. pass by reference.
    • Using pointers as function parameters.
  • Scope and Lifetime:
    • Local vs. global variables.
    • Static variables and their uses.
  • Recursive Functions:
    • Understanding recursion and base cases.
    • Writing recursive solutions for problems like factorial, Fibonacci series, etc.
  • Description: Functions promote code reusability and modularity, allowing complex programs to be broken down into manageable pieces. This module covers the creation and utilization of functions, parameter passing mechanisms, and the concept of recursion. Students will learn to write efficient recursive functions to solve problems that require repeated sub-solutions.
  • Practical Exercises:
  • Write and call user-defined functions for mathematical operations.
  • Implement functions with different parameter passing methods.
  • Develop recursive functions to compute factorial and Fibonacci numbers.
  • Create programs that demonstrate the use of static variables within functions.
  • Module 5: Arrays and Strings
  • Objective: To learn about arrays, multi-dimensional arrays, and string manipulation in C.
  • Topics:
  • One-Dimensional Arrays:
    • Declaration, initialization, and accessing array elements.
    • Traversing arrays using loops.
  • Multi-Dimensional Arrays:
    • Declaring and initializing two-dimensional and three-dimensional arrays.
    • Accessing and manipulating elements in multi-dimensional arrays.
  • String Handling:
    • Introduction to strings as character arrays.
    • Common string functions (strlen, strcpy, strcat, strcmp, etc.).
  • Array of Pointers:
    • Understanding pointers to arrays.
    • Manipulating arrays using pointers.
  • Dynamic Arrays:
    • Allocating and deallocating memory for arrays at runtime using malloc, calloc, realloc, and free.
  • Description: Arrays and strings are fundamental data structures in C that store collections of data. This module explores how to declare, initialize, and manipulate one-dimensional and multi-dimensional arrays. Additionally, students will delve into string handling, understanding how strings are represented and manipulated using standard library functions. The concept of pointers to arrays and dynamic memory allocation for arrays will also be covered.
  • Practical Exercises:
  • Declare and initialize arrays and access elements using indices.
  • Perform operations on multi-dimensional arrays (e.g., matrix multiplication).
  • Write programs to manipulate strings using various string functions.
  • Implement dynamic arrays that can grow or shrink based on user input.
  • Module 6: Pointers
  • Objective: To understand pointers, their uses, and pointer arithmetic in C.
  • Topics:
  • Introduction to Pointers:
    • Definition and importance of pointers.
    • Pointer syntax and declaration.
  • Pointer Operations:
    • Assigning addresses to pointers.
    • Dereferencing pointers to access data.
  • Pointer Arithmetic:
    • Incrementing and decrementing pointers.
    • Pointer comparisons and differences.
  • Pointers and Arrays:
    • Relationship between pointers and arrays.
    • Accessing array elements using pointers.
  • Pointers to Pointers:
    • Understanding multi-level pointers.
    • Applications of pointers to pointers.
  • Dynamic Memory Allocation:
    • Allocating memory at runtime using malloc, calloc, and realloc.
    • Freeing allocated memory using free.
  • Function Pointers:
    • Declaring and using pointers to functions.
    • Passing functions as arguments.
  • Description: Pointers are powerful features in C that provide direct memory access and efficient data manipulation. This module covers the basics of pointers, including their declaration, dereferencing, and arithmetic operations. Students will learn the close relationship between pointers and arrays, as well as advanced topics like pointers to pointers and function pointers. Practical applications of dynamic memory allocation using pointers will also be explored.
  • Practical Exercises:
  • Write programs that use pointers to access and modify variables.
  • Perform pointer arithmetic to traverse arrays.
  • Implement multi-level pointers to handle complex data structures.
  • Create dynamic arrays using pointers and memory allocation functions.
  • Use function pointers to implement callback functions.
  • Module 7: Structures and Unions
  • Objective: To learn about user-defined data types using structures and unions for complex data management.
  • Topics:
  • Structures:
    • Defining and declaring structures.
    • Accessing structure members.
    • Nested structures and arrays of structures.
  • Unions:
    • Definition and declaration of unions.
    • Differences between structures and unions.
    • Use cases for unions.
  • Pointers to Structures:
    • Accessing structure members using pointers.
    • Dynamic allocation of structures.
  • Typedef and Structures:
    • Using typedef to simplify structure declarations.
    • Creating aliases for complex data types.
  • Bit Fields:
    • Defining and using bit fields within structures.
    • Memory optimization using bit fields.
  • Description: Structures and unions allow the grouping of different data types into a single unit, facilitating the management of related data. This module introduces students to structures, their declaration, and usage, including nested structures and arrays of structures. Unions are explored as an alternative to structures when memory optimization is required. Advanced topics like pointers to structures, typedef for simplifying declarations, and bit fields for memory-efficient data storage are also covered.
  • Practical Exercises:
  • Define and use structures to store student records (name, age, grade).
  • Create arrays of structures and perform operations on them.
  • Implement unions to handle different data types within the same memory location.
  • Use pointers to structures for dynamic data management.
  • Define structures with bit fields and demonstrate memory savings.
  • Module 8: File Handling
  • Objective: To understand file operations in C for reading from and writing to files.
  • Topics:
  • Introduction to File Handling:
    • Importance of file operations in programming.
    • File types: Text files vs. binary files.
  • Basic File Operations:
    • Opening and closing files using fopen and fclose.
    • Reading from files using fgetc, fgets, fscanf.
    • Writing to files using fputc, fputs, fprintf.
  • File Pointers and Modes:
    • Understanding file pointers.
    • Different file modes (r, w, a, rb, wb, etc.).
  • Advanced File Operations:
    • Random access in files using fseek, ftell, rewind.
    • Error handling during file operations.
  • Working with Binary Files:
    • Reading and writing binary data.
    • Structuring binary file I/O.
  • File Manipulation:
    • Appending data to existing files.
    • Modifying specific parts of a file.
  • Description: File handling is essential for data persistence in applications. This module covers the fundamental concepts of file operations in C, including opening, reading, writing, and closing files. Students will learn to handle both text and binary files, perform random access operations, and implement error handling to manage file I/O effectively. Practical applications such as storing and retrieving structured data using files will be explored.
  • Practical Exercises:
  • Write programs to read and write data to text files.
  • Implement file copying and appending operations.
  • Create a program that stores and retrieves student records from a binary file.
  • Use fseek and ftell to navigate within a file.
  • Handle file I/O errors gracefully in programs.
  • Module 9: Dynamic Memory Allocation
  • Objective: To manage memory efficiently using dynamic memory allocation techniques in C.
  • Topics:
  • Understanding Memory Management:
    • Static vs. dynamic memory allocation.
    • Heap vs. stack memory.
  • Dynamic Memory Allocation Functions:
    • malloc(), calloc(), realloc(), and free().
    • Syntax and usage of each function.
  • Allocating Memory for Different Data Types:
    • Single variables, arrays, and structures.
  • Memory Leak Prevention:
    • Best practices for allocating and freeing memory.
    • Detecting and avoiding memory leaks.
  • Practical Applications:
    • Implementing dynamic data structures (e.g., linked lists, trees).
    • Resizable arrays using dynamic memory allocation.
  • Description: Efficient memory management is crucial for writing optimized C programs, especially when dealing with large data sets or dynamic data structures. This module introduces dynamic memory allocation in C, teaching students how to allocate and deallocate memory at runtime using functions like malloc, calloc, realloc, and free. Emphasis is placed on preventing memory leaks and managing memory effectively for different data types and structures.
  • Practical Exercises:
  • Allocate and deallocate memory for single variables and arrays.
  • Implement dynamic arrays that can resize based on user input.
  • Create a linked list using dynamic memory allocation.
  • Develop programs that demonstrate memory leak detection and prevention techniques.
  • Module 10: Advanced Topics and Project
  • Objective: To explore advanced programming concepts and apply all learned skills in a comprehensive project.
  • Topics:
  • Advanced Data Structures:
    • Linked lists, stacks, queues, trees, and graphs.
    • Implementing these data structures in C.
  • Recursion and Backtracking:
    • Advanced recursion techniques.
    • Solving complex problems using recursion and backtracking.
  • Bit Manipulation:
    • Understanding bits and bitwise operations.
    • Practical applications of bit manipulation.
  • Advanced Input/Output:
    • Handling user input more effectively.
    • Implementing robust I/O operations.
  • Project Development:
    • Planning and designing a comprehensive C project.
    • Implementing features using advanced programming techniques.
    • Testing and debugging the project for reliability and efficiency.
  • Description: This final module delves into advanced programming concepts that enhance the capability of C programmers to solve complex problems efficiently. Topics like advanced data structures, sophisticated recursion techniques, and bit manipulation are covered to broaden students’ programming skills. The module culminates in a capstone project where students apply all their knowledge to develop a substantial C application, reinforcing their learning through practical implementation.
  • Practical Exercises:
  • Implement advanced data structures such as binary trees and graphs.
  • Solve problems using recursive algorithms and backtracking.
  • Write programs that utilize bitwise operations for tasks like data compression or encryption.
  • Develop a comprehensive C project (e.g., a simple database system, game, or file manager) that incorporates multiple programming concepts learned throughout the course.
  • Assessment and Evaluation
  • Quizzes: Regular quizzes at the end of each module to reinforce learning and assess understanding.
  • Assignments: Practical assignments involving coding tasks related to each module’s topics.
  • Practical Labs: Hands-on lab sessions to implement and test concepts in real-time.
  • Mid-Term Exam: An examination covering the first half of the course content.
  • Final Project: A comprehensive project demonstrating the application of all learned concepts.
  • Final Exam: A written and practical exam covering the entire syllabus.
  • Recommended Resources
  • Books:
    • The C Programming Language by Brian W. Kernighan and Dennis M. Ritchie
    • C Programming: A Modern Approach by K. N. King
    • Head First C by David Griffiths and Dawn Griffiths
  • Online Tutorials:
  • Practice Platforms:
  • Hands-On Approach:
  • Interactive Sessions:
    • Conduct live coding sessions to demonstrate problem-solving techniques.
    • Facilitate group activities and pair programming to enhance collaborative skills.
  • Continuous Feedback:
    • Offer timely feedback on assignments and projects to guide student progress.
    • Create an open environment for questions and discussions to address learning challenges promptly.
  • Resource Accessibility:
    • Provide access to supplementary materials, coding examples, and reference guides.
    • Encourage the use of version control systems (e.g., Git) for managing code projects.
  • This detailed module-wise syllabus ensures that students will progressively build their proficiency in C programming, from fundamental concepts to advanced applications. The combination of theoretical knowledge and practical implementation prepares students to tackle real-world programming challenges confidently and efficiently.
  • HackerRank C Challenges
  • LeetCode C Problems
  • Encourage students to write code regularly to reinforce learning.
  • Provide real-world problem scenarios to apply programming concepts effectively.
  • multiple-choice questions (MCQs) organized by module based on the C Language Programming syllabus provided. Each question includes four answer options with the correct answer indicated.
  • Module 1: Introduction to C Programming
  • Q1. Who is considered the creator of the C programming language?
  • A) James Gosling
  • B) Bjarne Stroustrup
  • C) Dennis Ritchie
  • D) Guido van Rossum
    Answer: C) Dennis Ritchie
  • Q2. Which of the following is a fundamental feature of the C programming language?
  • A) Object-oriented programming
  • B) Platform independence
  • C) Low-level memory access
  • D) Automatic garbage collection
    Answer: C) Low-level memory access
  • Q3. What is the correct file extension for a C source file?
  • A) .cpp
  • B) .c
  • C) .cs
  • D) .java
    Answer: B) .c
  • Q4. Which of the following is the correct way to include a standard input-output library in a C program?
  • A) #include <stdio.h>
  • B) #include "stdio.h"
  • C) #include <stdlib.h>
  • D) #include "stdlib.h"
    Answer: A) #include <stdio.h>
  • Module 2: Data Types, Variables, and Operators
  • Q5. What is the size of an int data type in C on a 32-bit system?
  • A) 2 bytes
  • B) 4 bytes
  • C) 8 bytes
  • D) 16 bytes
    Answer: B) 4 bytes
  • Q6. Which of the following is a valid variable declaration in C?
  • A) int 1stNumber;
  • B) float $salary;
  • C) char name[20];
  • D) double class grade;
    Answer: C) char name[20];
  • Q7. What is the result of the expression 5 + 2 * 3 in C?
  • A) 21
  • B) 11
  • C) 15
  • D) 9
    Answer: B) 11
  • Q8. Which operator is used to obtain the address of a variable in C?
  • A) *
  • B) &
  • C) %
  • D) #
    Answer: B) &
  • Module 3: Control Structures
  • Q9. What is the output of the following code snippet?
  • #include<stdio.h>
  • int main() {
  • int a = 10;
  • if (a > 5)
  • printf(“Greater”);
  • else
  • printf(“Smaller”);
  • return 0;
  • }
  • A) Greater
  • B) Smaller
  • C) Nothing
  • D) Compilation Error
    Answer: A) Greater
  • Q10. Which loop will always execute its body at least once?
  • A) for loop
  • B) while loop
  • C) do-while loop
  • D) foreach loop
    Answer: C) do-while loop
  • Q11. What keyword is used to terminate a loop prematurely in C?
  • A) exit
  • B) stop
  • C) break
  • D) return
    Answer: C) break
  • Q12. How many times will the following loop execute?
  • for(int i = 0; i < 5; i++) {
  • printf(“%d “, i);
  • }
  • A) 4
  • B) 5
  • C) 6
  • D) Infinite
    Answer: B) 5
  • Module 4: Functions and Recursion
  • Q13. What is the return type of the main function in C?
  • A) void
  • B) int
  • C) float
  • D) char
    Answer: B) int
  • Q14. Which of the following is a correct way to declare a function that takes two integers and returns their sum?
  • A) int sum(int a, int b);
  • B) sum(int a, int b) -> int;
  • C) int sum(a, b) { return a + b; }
  • D) function sum(int a, int b) returns int;
    Answer: A) int sum(int a, int b);
  • Q15. What is the base case in a recursive function?
  • A) The case where the function calls itself
  • B) The condition under which the recursion stops
  • C) The first call to the function
  • D) The return statement
    Answer: B) The condition under which the recursion stops
  • Q16. What will be the output of the following recursive function when called with n = 3?
  • int factorial(int n)
  • { if(n == 0)
  • return 1;
  • else
  • return n * factorial(n-1);
  • }
  • A) 3
  • B) 6
  • C) 9
  • D) 1
    Answer: B) 6
  • Module 5: Arrays and Strings
  • Q17. How do you declare a one-dimensional array of integers with 10 elements in C?
  • A) int arr[10];
  • B) int arr(10);
  • C) int arr = [10];
  • D) int arr{10};
    Answer: A) int arr[10];
  • Q18. What is the output of the following code snippet ?
  • #include <stdio.h>
  • int main()
  • {
  • char str[] = “Hello”;
  • printf(“%c”, str[1]);
  • return 0;
  • }
  • A) H
  • B) e
  • C) l
  • D) o
    Answer: B) e
  • Q19. Which function is used to concatenate two strings in C?
  • A) strcpy()
  • B) strcmp()
  • C) strcat()
  • D) strlen()
    Answer: C) strcat()
  • Q20. What is the index of the first element in an array in C?
  • A) 0
  • B) 1
  • C) -1
  • D) It depends on the array size
    Answer: A) 0
  • Q21. How do you find the length of a string in C?
  • A) strlen(str)
  • B) strlength(str)
  • C) length(str)
  • D) sizeof(str)
    Answer: A) strlen(str)
  • Module 6: Pointers
  • Q22. What does the * operator do when used with a pointer variable?
  • A) Declares a pointer
  • B) Accesses the value at the pointed location (dereferencing)
  • C) Assigns a value to the pointer
  • D) Multiplies two values
    Answer: B) Accesses the value at the pointed location (dereferencing)
  • Q23. What is the output of the following code snippet ?
  • #include <stdio.h>
  • int main()
  • {
  • int a = 10;
  • int *p = &a;
  • printf(“%d”, *p);
  • return 0;
  • }
  • A) Address of a
  • B) Value of p
  • C) Value of a
  • D) Compilation Error
    Answer: C) Value of a
  • Q24. How do you declare a pointer to an integer in C?
  • A) int ptr;
  • B) int *ptr;
  • C) *int ptr;
  • D) pointer int ptr;
    Answer: B) int *ptr;
  • Q25. Which of the following statements is true about pointers?
  • A) Pointers store data values.
  • B) Pointers store memory addresses.
  • C) Pointers cannot be used with arrays.
  • D) Pointers are only used in functions.
    Answer: B) Pointers store memory addresses.
  • Module 7: Structures and Unions
  • Q26. How do you define a structure named Student with an integer id and a float grade ?
  • Answer: A)
  • Q27. What is the main difference between a structure and a union in C?
  • A) Structures use less memory than unions.
  • B) Unions allow storing different data types in the same memory location.
  • C) Structures can only contain integers.
  • D) Unions cannot be nested within structures.
    Answer: B) Unions allow storing different data types in the same memory location.
  • Q28. How do you access the grade member of a structure variable s?
  • A) s.grade
  • B) s->grade
  • C) grade.s
  • D) &s.grade
    Answer: A) s.grade
  • Q29. How do you declare an array of 5 structures of type Student?
  • A) struct Student students[5];
  • B) Student students[5];
  • C) struct students[5] Student;
  • D) Both A and B
    Answer: D) Both A and B
  • Q30. What keyword is used to create an alias for a structure in C?
  • A) struct
  • B) typedef
  • Module 8: File Handling
  • Q31. Which function is used to open a file for reading in C?
  • A) fopen("file.txt", "w");
  • B) fopen("file.txt", "r");
  • C) fopen("file.txt", "a");
  • D) fopen("file.txt", "rw");
    Answer: B) fopen("file.txt", "r");
  • Q32. What does the fclose() function do?
  • A) Opens a file
  • B) Closes an open file
  • C) Reads data from a file
  • D) Writes data to a file
    Answer: B) Closes an open file
  • Q33. Which function is used to read a single character from a file?
  • A) fread()
  • B) fgetc()
  • C) fgets()
  • D) fscanf()
    Answer: B) fgetc()
  • Q34. How do you write the string “Hello” to a file using fprintf?
  • A) fprintf(file, "Hello");
  • B) fprintf("Hello", file);
  • C) fprintf(file, %s, "Hello");
  • D) fprintf(file, 'Hello');
    Answer: A) fprintf(file, "Hello");
  • Q35. What mode should you use with fopen to append data to an existing file?
  • A) "r"
  • B) "w"
  • C) "a"
  • D) "rw"
    Answer: C) "a"
  • Q36. Which function is used to move the file pointer to a specific location in a file?
  • A) fseek()
  • B) ftell()
  • C) rewind()
  • D) fgets()
    Answer: A) fseek()
  • Module 9: Dynamic Memory Allocation
  • Q37. Which function is used to allocate memory for an array of 10 integers dynamically?
  • A) malloc(10);
  • B) malloc(10 * sizeof(int));
  • C) calloc(10, sizeof(int));
  • D) Both B and C
    Answer: D) Both B and C
  • Q38. What does the free() function do in C?
  • A) Allocates memory
  • B) Reallocates memory
  • C) Deallocates previously allocated memory
  • D) Checks memory usage
    Answer: C) Deallocates previously allocated memory
  • Q39. What will happen if you forget to free dynamically allocated memory in a C program?
  • A) The program will run faster
  • B) Memory leaks may occur
  • C) The program will not compile
  • D) The allocated memory will automatically be freed
    Answer: B) Memory leaks may occur
  • Q40. Which function is used to resize a previously allocated memory block?
  • A) malloc()
  • B) calloc()
  • C) realloc()
  • D) free()
    Answer: C) realloc()
  • Module 10: Advanced Topics and Project
  • Q41. What is a linked list in C?
  • A) A linear data structure where each element points to the next
  • B) A collection of arrays
  • C) A type of file handling method
  • D) A memory allocation technique
    Answer: A) A linear data structure where each element points to the next
  • Q42. Which of the following is a correct way to declare a pointer to a function that takes two integers and returns an integer?
  • A) int (*func)(int, int);
  • B) int func*(int, int);
  • C) (*int func)(int, int);
  • D) int *func(int, int);
    Answer: A) int (*func)(int, int);
  • Q43. What is the purpose of the static keyword when used inside a function?
  • A) To make the variable accessible outside the function
  • B) To allocate memory on the heap
  • C) To preserve the variable’s value between function calls
  • D) To make the variable global
    Answer: C) To preserve the variable’s value between function calls
  • Q44. Which of the following is a use case for bit manipulation in C?
  • A) Sorting arrays
  • B) Implementing encryption algorithms
  • C) Managing file I/O
  • D) Handling string operations
    Answer: B) Implementing encryption algorithms
  • Q45. What is recursion in C programming?
  • A) A loop that repeats indefinitely
  • B) A function that calls itself
  • C) A function that returns multiple values
  • D) A method to allocate memory dynamically
    Answer: B) A function that calls itself
  • Q46. How do you declare a pointer to a pointer of an integer in C?
  • A) int **ptr;
  • B) int *ptr*;
  • C) int ptr**;
  • D) **int ptr;
    Answer: A) int **ptr;
  • Q47. Which of the following is an example of a recursive problem?
  • A) Finding the maximum of two numbers
  • B) Calculating the factorial of a number
  • C) Sorting an array using the bubble sort algorithm
  • D) Reversing a string
    Answer: B) Calculating the factorial of a number
  • Q48. What is the output of the following code?
  • #include <stdio.h>
  • int main()
  • {
  • int a = 5;
  • int *p = &a;
  • int **pp = &p;
  • printf(“%d”, **pp);
  • return 0;
  • }
  • A) Address of a B) Value of p C) Value of a D) Address of p
  • Answer: C) Value of a
  • Q49. What does the following code do ?
  • struct Point
  • {
  • int x;
  • int y;
  • };
  • struct Point p1 = {10, 20};
  • A) Declares a structure named Point with members x and y and initializes p1 with values 10 and 20
  • B) Declares two separate variables x and y
  • C) Creates a union named Point
  • D) Defines a function named Point
    Answer: A) Declares a structure named Point with members x and y and initializes p1 with values 10 and 20
  • Q50. In C, what is the primary difference between struct and union?
  • A) Structures use more memory than unions
  • B) Unions can only hold one type of data at a time
  • C) Structures cannot be nested
  • D) Unions are faster than structures
    Answer: B) Unions can only hold one type of data at a time
  • Q51. What is the purpose of the typedef keyword in C?
  • A) To define constants
  • B) To create type aliases
  • C) To declare variables
  • D) To define macros
    Answer: B) To create type aliases
  • Q52. Which of the following is a correct way to allocate memory for an array of 5 integers using malloc?
  • A) int *arr = malloc(5);
  • B) int arr[5] = malloc(sizeof(int));
  • C) int *arr = (int*)malloc(5 * sizeof(int));
  • D) int *arr = malloc(sizeof(int) / 5);
    Answer: C) int *arr = (int*)malloc(5 * sizeof(int));
  • Q53. What will the following code print ?
  • #include <stdio.h>
  • int main()
  • {
  • char str[] = “C Programming”;
  • printf(“%s”, str + 2);
  • return 0;
  • }
  • A) “C Programming”
  • B) “Programming”
  • C) “Programming”
  • D) “Programming”
    Answer: C) “Programming”
  • Q54. Which of the following is used to handle errors in file operations?
  • A) feof()
  • B) ferror()
  • C) fflush()
  • D) fseek()
    Answer: B) ferror()
  • Q55. What is the purpose of the sizeof operator in C?
  • A) To determine the size of a variable or data type in bytes
  • B) To convert data types
  • C) To allocate memory
  • D) To compare two variables
    Answer: A) To determine the size of a variable or data type in bytes
  • Module 10: Advanced Topics and Project
  • Q56. Which of the following data structures is best suited for implementing a queue?
  • A) Array
  • B) Linked List
  • C) Stack
  • D) Binary Tree
    Answer: B) Linked List
  • Q57. What is the primary advantage of using recursion over iteration?
  • A) Recursion uses less memory
  • B) Recursion is faster
  • C) Recursion simplifies the code for problems that have a natural recursive structure
  • D) Recursion avoids stack overflow
    Answer: C) Recursion simplifies the code for problems that have a natural recursive structure
  • Q58. What does the following function do ?
  • int sum (int n)
  • {
  • if(n == 0)
  • return 0;
  • else
  • return n + sum(n-1);
  • }
  • A) Calculates the factorial of n
  • B) Calculates the sum of numbers from 1 to n
  • C) Calculates the power of n
  • D) Returns n
    Answer: B) Calculates the sum of numbers from 1 to n
  • Q59. Which bitwise operator is used to perform a left shift?
  • A) &
  • B) |
  • C) <<
  • D) >>
    Answer: C) <<
  • Q60. What is the output of the following code ?
  • #include <stdio.h>
  • int main()
  • {
  • int a = 5;
  • int *p = &a;
  • *p = 10;
  • printf(“%d”, a);
  • return 0;
  • A) 5
  • B) 10
  • C) Address of a
  • D) Compilation Error
    Answer: B) 10
  • Q61. How do you declare a pointer to a function that returns void and takes no arguments?
  • A) void *func();
  • B) void (*func)();
  • C) *void func();
  • D) void func*();
    Answer: B) void (*func)();
  • Q62. What is the correct syntax to free dynamically allocated memory pointed to by ptr?
  • A) free(*ptr);
  • B) free(ptr);
  • C) delete ptr;
  • D) free(&ptr);
    Answer: B) free(ptr);
  • Q63. Which of the following is true about static variables inside a function?
  • A) They are reinitialized every time the function is called
  • B) They retain their value between function calls
  • C) They are stored in the stack memory
  • D) They cannot be accessed outside the function
    Answer: B) They retain their value between function calls
  • Q64. What does the following code snippet do?
  • A) Prints 1
  • B) Prints 2
  • C) Prints 3
  • D) Causes a segmentation fault
    Answer: C) Prints 3
  • Q65. Which function is used to compare two strings in C?
  • A) strcpy()
  • B) strcat()
  • C) strcmp()
  • D) strlen()
    Answer: C) strcmp()
  • Q66. What is the purpose of the fseek() function in file handling?
  • A) To close a file
  • B) To read from a file
  • C) To move the file pointer to a specific location
  • D) To write to a file
    Answer: C) To move the file pointer to a specific location
  • Q67. In dynamic memory allocation, which function initializes the allocated memory to zero?
  • A) malloc()
  • B) calloc()
  • C) realloc()
  • D) free()
    Answer: B) calloc()
  • Q68. What will the following code print ?
  • #include <stdio.h>
  • int main()
  • {
  • int a = 10;
  • int *p = &a;
  • int **pp = &p;
  • printf(“%d”, **pp);
  • return 0;
  • }
  • A) Address of a
  • B) Address of p
  • C) Value of a
  • D) Value of p
    Answer: C) Value of a
  • Q69. Which of the following is a valid way to declare an array of 5 pointers to integers?
  • A) int *arr[5];
  • B) int arr*[5];
  • C) int (*arr)[5];
  • D) int arr**5;
    Answer: A) int *arr[5];
  • Q70. What is the output of the following code ?
  • #include <stdio.h>
  • int main()
  • {
  • char str[] = “C Programming”;
  • char *p = str; p += 2;
  • printf(“%s”, p);
  • return 0;
  • }
  • A) “C Programming”
  • B) “Programming”
  • C) “Programming”
  • D) “Programming”
    Answer: B) “Programming”
  • Q71. How do you declare a two-dimensional array of integers with 3 rows and 4 columns?
  • A) int arr[3][4];
  • B) int arr(3,4);
  • C) int arr[4][3];
  • D) int arr{3,4};
    Answer: A) int arr[3][4];
  • Q72. Which of the following is NOT a valid file mode in fopen()?
  • A) "r"
  • B) "w"
  • C) "x"
  • D) "b"
    Answer: D) "b"
    (Explanation: "b" is not a standalone mode; it is used as a suffix like "rb" or "wb" for binary mode.)
  • Q73. What does the fprintf() function do?
  • A) Reads formatted input from a file
  • B) Writes formatted output to a file
  • C) Opens a file
  • D) Closes a file
    Answer: B) Writes formatted output to a file
  • Q75. What is the purpose of the typedef keyword when used with structures?
  • A) To define a structure
  • B) To create an alias for a structure type
  • C) To initialize a structure
  • D) To inherit from another structure
    Answer: B) To create an alias for a structure type
  • Q76. How do you access the y member of the structure pointed to by p?
  • A) p.y
  • B) *p.y
  • C) (*p).y
  • D) p->y
    Answer: D) p->y
  • Q78. What will the following code output ?
  • #include <stdio.h>
  • int main()
  • {
  • char str[] = “Data”;
  • printf(“%c”, *(str + 2));
  • return 0;
  • }
  • A) D
  • B) a
  • C) t
  • D) Data
    Answer: C) t
  • Q79. Which of the following statements correctly reallocates memory for an integer pointer ptr to hold 20 integers?
  • A) ptr = realloc(ptr, 20);
  • B) ptr = realloc(ptr, 20 * sizeof(int));
  • C) ptr = realloc(ptr, sizeof(int));
  • D) realloc(ptr, 20 * sizeof(int));
    Answer: B) ptr = realloc(ptr, 20 * sizeof(int));
  • Q80. What is the purpose of the fgets() function in C?
  • A) To read a single character from a file
  • B) To read a formatted string from a file
  • C) To read a string from a file with buffer size limitation
  • D) To write a string to a file
    Answer: C) To read a string from a file with buffer size limitation
  • Q81. How do you declare a pointer to an array of 10 integers in C?
  • A) int *arr[10];
  • B) int (*arr)[10];
  • C) int arr*10;
  • D) int arr**10;
    Answer: B) int (*arr)[10];
  • Q82. Which of the following is true about struct in C?
  • A) All members share the same memory location
  • B) Members are stored in contiguous memory locations
  • C) Structures cannot contain other structures
  • D) Structures are not user-defined types
    Answer: B) Members are stored in contiguous memory locations
  • Q83. What is the output of the following code ?
  • #include <stdio.h>
  • int main()
  • {
  • int a = 5,
  • b = 10;
  • int *p = &a, *q = &b;
  • printf(“%d”, *p + *q);
  • return 0;
  • }
  • A) Address of a + Address of b
  • B) 15
  • C) 510
  • D) Compilation Error
    Answer: B) 15
  • Q84. Which of the following is used to read formatted input from a file?
  • A) fscanf()
  • B) fprintf()
  • C) fgets()
  • D) fgetc()
    Answer: A) fscanf()
  • Q85. How do you declare a two-dimensional array of characters to store 5 strings, each up to 20 characters?
  • A) char arr[5][20];
  • B) char arr[20][5];
  • C) char *arr[5][20];
  • D) char arr(5, 20);
    Answer: A) char arr[5][20];
  • Q86. What is the purpose of using typedef with a struct?
  • A) To allocate memory for the structure
  • B) To simplify the syntax when declaring structure variables
  • C) To prevent the structure from being modified
  • D) To create nested structures
    Answer: B) To simplify the syntax when declaring structure variables
  • Q87. Which of the following is NOT a valid way to access members of a structure using a pointer?
  • A) (*p).member
  • B) p->member
  • C) *p.member
  • D) All are valid
    Answer: C) *p.member
  • Q88. What will the following code output ?
  • #include <stdio.h>
  • int main()
  • {
  • int a = 10;
  • int *p = &a;
  • printf(“%p”, (void*)p);
  • return 0;
  • }
  • A) 10B) Address of aC) Compilation ErrorD) Undefined behavior
  • Answer: B) Address of a
  • Q90. What does the strlen() function return?
  • A) The length of a string including the null terminator
  • B) The length of a string excluding the null terminator
  • C) The first character of a string
  • D) The last character of a string
    Answer: B) The length of a string excluding the null terminator
  • Q91. Which of the following is used to dynamically allocate memory for a structure?
  • A) malloc(sizeof(structure));
  • B) calloc(sizeof(structure));
  • C) realloc(sizeof(structure));
  • D) Both A and B
    Answer: D) Both A and B
  • Q92. How do you pass an array to a function in C?
  • A) By value
  • B) By reference
  • C) Using pointers
  • D) Both B and C
    Answer: D) Both B and C
  • Q93. What is the purpose of the return statement in a function?
  • A) To end the program
  • B) To exit the current function and optionally return a value
  • C) To call another function
  • D) To declare a variable
    Answer: B) To exit the current function and optionally return a value
  • Q94. Which of the following correctly declares a function that returns a pointer to an integer?
  • A) int *func();
  • B) int func*();
  • C) *int func();
  • D) int func*();
    Answer: A) int *func();
  • Q95. What will be the value of a after the following code is executed ?
  • #include <stdio.h>
  • int main()
  • {
  • int a = 5;
  • int *p = &a;
  • *p += 10;
  • return 0;
  • }
  • A) 5
  • B) 10
  • C) 15
  • D) Undefined
    Answer: C) 15
  • Q96. How do you initialize a pointer to NULL in C?
  • A) int *p = NULL;
  • B) int *p = 0;
  • C) int *p; p = NULL;
  • D) All of the above
    Answer: D) All of the above
  • Q97. Which of the following is a correct way to declare a function that takes a pointer to an integer as an argument and returns void?
  • A) void func(int p);
  • B) void func(int *p);
  • C) void func(*int p);
  • D) void func(&int p);
    Answer: B) void func(int *p);
  • Q98. What is the purpose of using pointers in C?
  • A) To increase program speed
  • B) To enable dynamic memory allocation and efficient array handling
  • C) To simplify syntax
  • D) To store multiple values in a single variable
    Answer: B) To enable dynamic memory allocation and efficient array handling
  • Q99. Which of the following statements is used to exit a loop immediately?
  • A) continue;
  • B) exit;
  • C) break;
  • D) return;
    Answer: C) break;
  • Q100. How do you declare a function prototype in C?
  • A) int func() { }
  • B) int func();
  • C) func int();
  • D) function int func();
    Answer: B) int func();
  • MCQs comprehensively cover the topics outlined in the C Language Programming syllabus. They can be used to assess students’ understanding of fundamental and advanced C programming concepts effectively.
error: Content is protected !!