Found 1339 Articles for C

Difference between const char* p, char * const p, and const char * const p in C

Mahesh Parahar
Updated on 06-Jan-2020 06:30:36

13K+ Views

PointerIn C programming language, *p represents the value stored in a pointer and p represents the address of the value, is referred as a pointer.const char* and char const* says that the pointer can point to a constant char and value of char pointed by this pointer cannot be changed. But we can change the value of pointer as it is not constant and it can point to another constant char.char* const says that the pointer can point to a char and value of char pointed by this pointer can be changed. But we cannot change the value of pointer ... Read More

Difference between const int*, const int * const, and int const * in C

Mahesh Parahar
Updated on 06-Jan-2020 06:27:49

4K+ Views

PointerIn C programming language, *p represents the value stored in a pointer and p represents the address of the value, is referred as a pointer.const int* and int const* says that the pointer can point to a constant int and value of int pointed by this pointer cannot be changed. But we can change the value of pointer as it is not constant and it can point to another constant int.const int* const says that the pointer can point to a constant int and value of int pointed by this pointer cannot be changed. And we cannot change the value ... Read More

Difference between %d and %i format specifier in C language.

Mahesh Parahar
Updated on 06-Jan-2020 06:22:05

13K+ Views

Format SpecifiersIn C programming language, %d and %i are format specifiers as where %d specifies the type of variable as decimal and %i specifies the type as integer. In usage terms, there is no difference in printf() function output while printing a number using %d or %i but using scanf the difference occurs. scanf() function detects base using %i but assumes base 10 using %d.Example (C) Live Demo#include int main() {    int num1 ,num2;    int num3, num4;    scanf("%i%d", &num1 , &num2);    printf("%i\t%d", num1, num2);    num3 = 010;    num4 = 010;    printf("%i\t%d", num3, num4); ... Read More

C/C++ difference's between "int main()" and "int main(void)"

Mahesh Parahar
Updated on 06-Jan-2020 06:19:29

955 Views

CIn C programming language, if a function signature is not having any parameters then it can take multiple arguments as input but the same is not true with C++. The compilation will fail if arguments are passed to such a function in C++. This is reason int main() and int main(void) are same in C, but int main(void) is better approach, which restricts the user to pass multiple arguments to main function.Example (C) Live Demo#include int main() {    static int counter = 3;    if (--counter){       printf("%d ", counter);       main(5);    } }Output2 ... Read More

Why is a[i] == i[a] in C/C++ arrays?

Arnab Chakraborty
Updated on 03-Jan-2020 11:15:27

329 Views

Here we will see one amazing trick in C or C++. The array subscript A[i] can also be written as i[a]. In C/C++ E1[E2] is defined as (*((E1) + (E2))). The compiler performs arithmetic internally to access the array elements. Because of the conversion of rules, that is applied to the binary + operator, if E1 is an array object, and E2 is an integer, then E1[[E2] signifies the E2th element in the E1 array. So A[B] can be defined as *(A + B), so B[A] = *(B + A). so they are basically the same thing.Example Live Demo#include using ... Read More

Unary operators in C/C++

Arnab Chakraborty
Updated on 03-Jan-2020 11:14:06

2K+ Views

Here we will see what are the unary operators in C / C++. Unary operator is operators that act upon a single operand to produce a new value. The unary operators are as follows.OperatorDescriptionIndirection operator (*)It operates on a pointer variable and returns an l-value equivalent to the value at the pointer address. This is called "dereferencing" the pointer.Address-of operator (&)The unary address-of operator (&) takes the address of its operand. The operand of the address-of operator can be either a function designator or an l-value that designates an object that is not a bit field and is not declared ... Read More

How to sort an array of dates in C/C++?

Arnab Chakraborty
Updated on 03-Jan-2020 10:52:24

914 Views

Suppose we have an array of dates. Here we will see how to sort then using C or C++ code. The dates are stored in a class (struct can be used in C also). We will use the sort function of the C++ STL. For comparing dates, we have to write our own compare function that will be used in the sort function. Let us see the example to get better view.Example Live Demo#include #include #include using namespace std; class Date {    public:       int d, m, y; }; bool compare(const Date &date1, const Date &date2){    if ... Read More

Print colored message with different fonts and sizes in C

sudhir sharma
Updated on 03-Jan-2020 08:05:02

3K+ Views

C/C++ programming language, the user is provided with functionality to customize the output based on the requirement of the user. C/C++ graphics functions are included in graphics.h header file. Using this library you can create different objects, set the color of text, change the font and size of the text and change the background of the output.Now, let's see the working of all the function to alter the text of the output in c/c++ programming language −setcolor() − This function is used to change the color of the output text.Syntaxsetcolor(int)Example#include #include int main(){    int gdriver = DETECT, gmode, i; ... Read More

Binary Search (Recursive and Iterative) in C Program

sudhir sharma
Updated on 26-Jun-2024 23:40:25

84K+ Views

Binary Search is a search algorithm that is used to find the position of an element (target value ) in a sorted array. The array should be sorted prior to applying a binary search. Binary search is also known by these names, logarithmic search, binary chop, half interval search. Working of Binary Search The binary search algorithm works by comparing the element to be searched by the middle element of the array and based on this comparison follows the required procedure. Case 1 − element = middle, the element is found return the index. Case 2 − element > middle, ... Read More

C Program for Activity Selection Problem

sudhir sharma
Updated on 03-Jan-2020 07:08:44

6K+ Views

The activity selection problem is a problem in which we are given a set of activities with their starting and finishing times. And we need to find all those activities that a person can do performing the single activity at a time.The greedy algorithm is appointed in this problem to select the next activity that is to be performed. Let’s first understand the greedy algorithm.Greedy Algorithm is an algorithm that tries to find the solution to a problem by finding the solution step by step. For selecting the next step, the algorithm also selected the step that seems to be ... Read More

Advertisements