Quantcast
Channel: C Programming Archives - QnA Plus
Browsing all 93 articles
Browse latest View live

Custom Deleter in std::unique_ptr

In the previous article, we saw how std::unique_ptr helps to clean memory. Generally it calls the default deleter (C++ delete operator) in appropriate time to clean up the allocated memory. But many...

View Article


Move std::unique_ptr to Pass to a Function or Assign to Another Variable

The std::unique_ptr has unique ownership of the object it manages. That means only one std::unique_ptr can contain the actual object pointer. That’s why we can not assign a std::unique_ptr to another...

View Article


C Program to Merge Two Sorted Arrays into one Sorted Array

Here we’ll write a C function to merge two sorted arrays into one. The merged array will also be sorted. Here we’ll use two sorted integer arrays that are sorted in ascending order. After merging the...

View Article

Image may be NSFW.
Clik here to view.

C Program to Find Minimum and Maximum Numbers in an Array

Here we’ll see how to write C program to find the minimum and maximum numbers in an array. #include <stdio.h> int main() { int arr[128]; int n = 0, i = 0, min = 0, max = 0; printf("Enter the...

View Article

Image may be NSFW.
Clik here to view.

C Program to Calculate Factorial of a Number

Factorial of a number N, (N!) is 1*2*3*4*5*…..*N. Here we’ll see how to write C program to calculate the factorial value of a number. Here are the C functions that calculate the factorial value of a...

View Article


Change a Variable from inside a C Function

Here we’ll see how we can change a variable from inside a C function. Let’s consider the following code snippet. #include <stdio.h> void change_value(int v) { printf("Value of input variable in...

View Article

Change a Pointer from inside a C Function

We can change normal variable from inside a C function by passing the pointer of the variable. Here we’ll see how to change a pointer variable from inside a C function. Concept is same, here we have...

View Article

Image may be NSFW.
Clik here to view.

C Program to Check a Bit of an Integer

An integer consists of 32 bits. Here we’ll see how to write C program to check whether a particular bit is 0 or 1. The above diagram shows the binary representation of an integer 8,55,119. Bit...

View Article


Image may be NSFW.
Clik here to view.

C Program to Copy an Array to Another

We can not copy an array using simple assignment operation like any other primitive data types. Here we’ll discuss the techniques to copy an array from one to another. By Traversing We can copy an...

View Article


Image may be NSFW.
Clik here to view.

Count Occurrences of a Substring in a String in C

Here we’ll see how to write C program to find out the number of occurrences of a substring in a string. C string library (<string.h>) provides a function (strstr()) to determine whether a...

View Article

Image may be NSFW.
Clik here to view.

C Program to Count Characters, Words and Lines in a File

To get a quick summary like total number of characters, words and limes in a file, Linux already has a tool, wc. Here we’ll see how to write C program to get the similar information. Strategy to Count...

View Article

Image may be NSFW.
Clik here to view.

C Program to Reverse a Linked List

Reversing a linked list means re-arranging the next (connection) pointers. Head will point to the last node and the first node will point to NULL. Direction of other next pointers will change. If a...

View Article

C Program to Swap Two Numbers

Here we’ll discuss about different techniques how we can swap two numbers. Swapping two numbers means exchanging the values of two variables. For example, if value of A is 5 and value of B is 10, then...

View Article


Image may be NSFW.
Clik here to view.

C Program to Delete the First Node of a Linked List

Here we’ll see how write C program to delete the first node of a linked list. Head always points to the first node. Head will move to where the first node is currently pointing to. First node can...

View Article

Image may be NSFW.
Clik here to view.

C Program to Delete the Last Node of a Linked List

Here we’ll see how to delete the last node of a linked list. The last node always points to NULL. To delete that, we have to traverse up to last node. We have to point the second last node to NULL and...

View Article


Image may be NSFW.
Clik here to view.

C Program to Move the Last Node to the Front of a Linked List

Here we’ll see how to write C Program to move the last node to the front of a linked list. We can do that just by re-arranging the pointers. No need to create or delete any node. Logic to Move the...

View Article

Image may be NSFW.
Clik here to view.

C Program to Set, Clear and Toggle a Bit

In this article we saw how to check a particular bit of a number. Here we’ll see how to set, clear or toggle a bit of a number. Setting a Bit Setting a bit means making that bit 1 irrespective of the...

View Article


Image may be NSFW.
Clik here to view.

C Program to Toggle Bits

Here we’ll see how to write C program to toggle all bits or a particular bit or all but a particular bit of a number. Toggle All Bits of a Number We can toggle all bits of a number using NOT (~)...

View Article

Image may be NSFW.
Clik here to view.

Left and Right Rotate Bits of a Number in C

Here we’ll see how to write C program to left or right rotate bits of a number. For example, an unsigned integer consists of 32-bit. Number 2591458749 is represented as...

View Article

Image may be NSFW.
Clik here to view.

Brian Kernighan’s Algorithm to Count the Set Bits of a Number

To count all set bits of a number, we can loop through all the bits and check whether any bit is set. For example, an integer has 32 bits. We can check all 32 bits in a loop to count the set (1) bits....

View Article
Browsing all 93 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>