Found 27759 Articles for Server Side Programming

Const member functions in C++

Samual Sam
Updated on 24-Jun-2020 11:19:02

16K+ Views

The const member functions are the functions which are declared as constant in the program. The object called by these functions cannot be modified. It is recommended to use const keyword so that accidental changes to object are avoided.A const member function can be called by any type of object. Non-const functions can be called by non-const objects only.Here is the syntax of const member function in C++ language, datatype function_name const();Here is an example of const member function in C++, Example Live Demo#include using namespace std; class Demo {    int val;    public:    Demo(int x = 0) { ... Read More

Ceil and floor functions in C++

karthikeya Boyini
Updated on 24-Jun-2020 11:19:37

4K+ Views

The ceil FunctionThe ceil function returns the smallest possible integer value which is equal to the value or greater than that. This function is declared in “cmath” header file in C++ language. It takes single value whoes ceil value is to be calculated. The datatype of variable should be double/float/long double only.Here is the syntax of ceil function in C++ language, double ceil(double x); float ceil(float x);Here is an example of ceil function in C++ language, Example Live Demo#include #include using namespace std; int main() {    float var = 1234.25;    float res;    res = ceil(var);   ... Read More

new and delete operator in C++

Samual Sam
Updated on 24-Jun-2020 11:20:50

14K+ Views

The new operatorThe new operator requests for the memory allocation in heap. If the sufficient memory is available, it initializes the memory to the pointer variable and returns its address.Here is the syntax of new operator in C++ language, pointer_variable = new datatype;Here is the syntax to initialize the memory, pointer_variable = new datatype(value);Here is the syntax to allocate a block of memory, pointer_variable = new datatype[size];Here is an example of new operator in C++ language, Example#include using namespace std; int main () {    int *ptr1 = NULL;    ptr1 = new int;    float *ptr2 = new ... Read More

CHAR_BIT in C++

karthikeya Boyini
Updated on 24-Jun-2020 11:21:26

529 Views

The CHAR_BIT is the number of bits in char. It is declared in “limits.h” header file in C++ language. It is of 8-bits per byte.Here is an example of CHAR_BIT in C++ language,Example Live Demo#include using namespace std; int main() {    int x = 28;    int a = CHAR_BIT*sizeof(x);    stack s;    cout

swap() function in C++

Samual Sam
Updated on 24-Jun-2020 11:22:01

20K+ Views

The swap() function is used to swap two numbers. By using this function, you do not need any third variable to swap two numbers.Here is the syntax of swap() in C++ language, void swap(int variable_name1, int variable_name2);If we assign the values to variables or pass user-defined values, it will swap the values of variables but the value of variables will remain same at the actual place.Here is an example of swap() in C++ language, Example Live Demo#include using namespace std; int main() {    int x = 35, y = 75;    printf("Value of x :%d", x);    printf("Value of ... Read More

What is Array Decay in C++?

Samual Sam
Updated on 24-Jun-2020 11:11:21

2K+ Views

The loss of type and dimensions of an array is known as array decay. It occurs when we pass the array into a function by pointer or value. First address is sent to the array which is a pointer. That is why, the size of array is not the original one.Here is an example of array decay in C++ language,Example Live Demo#include using namespace std; void DisplayValue(int *p) {    cout

Strings in C Language

Samual Sam
Updated on 24-Jun-2020 11:12:17

985 Views

String is an array of characters and terminated by a null character (\0). The null character is not placed by the user, the compiler places it at the end of string automatically.The difference between an array and a string is that the compiler does not place null character at the end of array while in string, compiler places null character.Here is the syntax of string in C language, char myStr[size];Here, myStr: The stringsize: Set the size of stringInitialize string in C language like show below −char myStr[size] = “string”; char myStr[size] = { ‘s’, ’t’, ’r’, ’i’, ’n’, ’g’, ’\0’ ... Read More

Arrays in C Language

karthikeya Boyini
Updated on 24-Jun-2020 11:12:39

825 Views

Array is a collection of same type of elements at contiguous memory location. The lowest address corresponds to the first element while highest corresponds to last element.Array index starts with zero(0) and ends with the size of array minus one(array size - 1). Array size must be integer greater than zero.Let us see an example, If array size = 10 First index of array = 0 Last index of array = array size - 1 = 10-1 = 9Here is the syntax of arrays in C language, type array_name[array_size ];The following is how you can initialize an array.type array_name[array_size] = ... Read More

Convert a String to Uppercase in C

Samual Sam
Updated on 04-Oct-2023 14:05:42

26K+ Views

Here is the program to convert a string to uppercase in C language,Example#include #include int main() {    char s[100];    int i;    printf("Enter a string : ");    gets(s);    for (i = 0; s[i]!='\0'; i++) {       if(s[i] >= 'a' && s[i] = 'a' && s[i]

For Versus While Loop in C

karthikeya Boyini
Updated on 24-Jun-2020 11:13:48

357 Views

For LoopThe for loop is a repetition control structure. It executes the statements a specific number of times. First, it takes the initial value from where it starts the iterations. Second, it takes the condition, which is checked for true, or false. At the end, it increment/ decrement and update the loop variables.Here is the syntax of for loop in C language,for ( init; condition; increment ) {    statement(s); }Here is an example of for loop in C language,Example Live Demo#include int main () {    int a = 5;    for(int i=0;i

Advertisements