This is the repository where I track what I learn in C++. Syntax is the same in C and C++ unless in specific scenarios such as Header Files, Function Overloading, or Object-Oriented Programming.
Some questions remain untouched because I can't understand how to solve them at my current level. If you know how to solve them in a beginner-friendly way, please lend a helping hand. Your contributions will help a lot of people.
- Declare an integer variable named
counter
and initialize it to 5.
- Write a C expression using the modulus operator (%) to find the remainder when 15 is divided by 4.
- Implement a C program that checks if a given number is even or odd and prints the result.
- Write a C program that uses a
switch
statement to display the name of a day based on the user's input (1 for Sunday, 2 for Monday, etc.). - Write a C program that generates the Fibonacci sequence up to the 10th term using a loop.
- Declare an array of integers named
scores
with a size of 3 and initialize it with values 85, 90, and 78.
- Write a C program that initializes an array of integers with values 1 to 5 and prints each element.
- Write a C program that searches for a specific value in an array of integers. Print the index if found; otherwise, print a message indicating its absence.
-
Declare a 2D array named
matrix
with 3 rows and 4 columns, and initialize it with some values. -
Implement a C program that uses a loop to find and print the maximum value in a matrix.
-
Write a C function called
calculateAverage
that takes an array of integers and its size as parameters and returns the average of the elements. -
Create a function
calculateSum
that takes an array of integers and its size as parameters and returns the sum of the elements. -
Create a C program that uses the function
calculateSum
to calculate the average of an array. -
Write a C function to check if a given number is prime or not.
-
(Unsolved) Implement a C function called
mergeArrays
that takes two arrays of integers and their sizes as parameters. Merge the arrays into a new array and return the result.
- In C, there is no direct support for function overloading. Discuss why function overloading is not available in C, unlike in C++.
- Implement a recursive C function to calculate the factorial of a given positive integer.
- Declare an integer variable
num
and a pointerptr
to an integer. Initializeptr
to point to the address ofnum
. Change the value ofnum
through the pointer to42
. - Create a pointer
p
and initialize it to point to the middle element of the array.
- Allocate memory dynamically for an array of 10 integers using
malloc
in C ornew
in C++. Free the dynamically allocated memory usingfree
in C ordelete
in C++.
- Write a C function called
swap
that takes two integer pointers as parameters and swaps the values they point to.
- Declare an array of integers and a pointer to the array. Use pointer arithmetic to print the elements of the array in reverse order.
- Create a function that accepts a string (character array) and returns the length of the string using pointers.
- Declare a structure named
Book
with memberstitle
,author
, andprice
. Create and initialize a structure variable for a book of your choice.
- Create a structure named
Date
with membersday
,month
, andyear
. Write a function to print the date in the format "dd-mm-yyyy."
- Declare a structure named
Student
with membersname
,rollNumber
, andmarks
. Create an array of structures to store information for five students.
- Extend the
Student
structure to include an array of grades for each student. Initialize the grades for a couple of students.
- Declare a structure named
Department
with membersname
andlocation
. Include this structure as a member of theCollege
structure, which also has members forname
andyearEstablished
.
- (Unsolved) Write a function that accepts an array of
Book
structures and prints the details of the book with the highest price.
- Write a program that uses a pointer to a structure to dynamically allocate memory for a single
Person
structure. Allow the user to input the person's details.
- Declare a union named
Value
with membersinteger
,decimal
, andcharacter
. Write a program to demonstrate the use of the union to store and print different types of values.
- Extend the
Value
union to include an array of integers. Write a program to initialize and print the values of the union members.
- Create a structure named
Employee
with membersname
and a union namedSalary
containing members formonthlySalary
(float) andhourlyRate
(float). The structure should indicate whether the salary is monthly or hourly.
-
(Unsolved) Modify the
calculateAverage
function from a previous example to also return the sum of the elements. Update the main function to print both average and sum. -
Create a function that sorts an array of integers in ascending order.
-
(Unsolved) Research and implement a C function that takes a variable number of arguments and calculates their sum.