Server Side Programming Articles - Page 1955 of 2650

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

14K+ 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

964 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

Difference between the Ternary operator and Null coalescing operator in php

Mahesh Parahar
Updated on 06-Jan-2020 06:15:23

496 Views

Ternary operatorTernary operator is used to replace if else statements into one statement.Syntax(condition) ? expression1 : expression2;Equivalent Expressionif(condition) {    return expression1; } else {    return expression2; }If condition is true, then it returns result of expression1 else it returns result of expression2. void is not allowed in condition or expressions.Null coalescing operatorNull coalescing operator is used to provide not null value in case the variable is null.Syntax(variable) ?? expression;Equivalent Expressionif(isset(variable)) {    return variable; } else {    return expression; }If variable is null, then it returns result of expression.Example    PHP Example     Outputnot passed not passed

Construct BST from its given level order traversal in C++

Arnab Chakraborty
Updated on 03-Jan-2020 11:42:38

407 Views

Suppose we have one level order traversal. From this traversal. we have to generate the tree So if the traversal is like [7, 4, 12, 3, 6, 8, 1, 5, 10], then the tree will be like −To solve this, we will use recursive approach. The first element will be the root. The second element will be the left child, and third element will be right child (If the condition of BST satisfies), this property will be satisfied for all elements. So we will follow these steps −At first we have to take the first element of the array, and ... Read More

Construct BST from given preorder traversal - Set 2 in C++

Arnab Chakraborty
Updated on 03-Jan-2020 11:39:48

224 Views

Suppose we have one pre order traversal. From this traversal. we have to generate the tree So if the traversal is like [10, 5, 1, 7, 40, 50], then the tree will be like −To solve this, we will follow these steps −Create empty stackMake the first value as root, and push it into stack.Now keep pooping while the stack is not empty and the next value is greater than stack top element, make this as right child of the last popped node. Now push the new node to the stack.When the next value is less than the top element, ... Read More

Construct BST from given preorder traversal - Set 1 in C++

Arnab Chakraborty
Updated on 03-Jan-2020 11:36:03

192 Views

Suppose we have one pre order traversal. From this traversal. we have to generate the tree So if the traversal is like [10, 5, 1, 7, 40, 50], then the tree will be like −To solve this, we will use this trick. The trick is to set a range {min… max} for each node. At first we will initialize the range as {INT_MIN… INT_MAX}. The first node will definitely be in range, so after that we will create root node. To construct the left subtree, set the range as {INT_MIN… root->data}. If a values is in the range {INT_MIN… root->data}, ... Read More

Construct a Turing Machine for language L = {wwr | w ∈ {0, 1}}

Arnab Chakraborty
Updated on 03-Jan-2020 11:31:12

6K+ Views

Here we will see how to make a Turing machine for language L = {WWr |W belongs to {0, 1}}. So this represents a kind of language where we will use only two characters 0s and 1s. The w is a string and wr is reverse of it. So if w = 10110, then wr will be 01101. So the Turing machine will accept the string z = 1011001101.To solve this, we will use this approach. First check the first symbol, if it’s 0 then replace it using y and if that is 1, then replace using x. Then go ... Read More

Construct a Turing Machine for language L = {ww | w ∈ {0,1}}

Arnab Chakraborty
Updated on 03-Jan-2020 11:29:23

7K+ Views

Here we will see how to make a Turing machine for language L = {WW |W belongs to {0, 1}}. So this represents a kind of language where we will use only two characters 0s and 1s. The w is a string. So if w = 10110, so the Turing machine will accept the string z = 1011010110.To solve this, we will use this approach. The first thing is to find the midpoint of the string, we will convert a 0 to x and 1 to y. After continuously doing it a point is reached when all 0’s and 1’s ... Read More

Construct a Turing Machine for language L = {0n1n2n | n≥1}

Arnab Chakraborty
Updated on 03-Jan-2020 11:28:08

5K+ Views

Here we will see how to make a Turing machine for language L = {0n1n2n | n ≥ n}. So this represents a kind of language where we will use only three characters 0s, 1s and 2s. The w is a string. So if w = 000111222, The Turing machine will accept it.To solve this, we will use this approach. First replace one 0 from front by x, then keep moving right till we get one 1 and replace this 1 by y. Again, keep moving right till we get one 2, replace it by z and move left. Now ... Read More

Advertisements