Server Side Programming Articles - Page 1851 of 2650

Initialization of a multidimensional arrays in C/C++ Program

Ayush Gupta
Updated on 23-Mar-2020 08:39:05

201 Views

In this tutorial, we will be discussing a program to understand how to initiate a multidimensional array in C/C++.While declaring a multidimensional array, the value of the leftmost dimension can be left empty, but all other dimensions must be provided.Example Live Demo#include int main(){    int a[][2] = {{1,2},{3,4}};    printf("%lu", sizeof(a));    getchar();    return 0; }Output16

Extended Integral Types (Choosing the correct integer size in C/C++)

Ayush Gupta
Updated on 23-Mar-2020 08:37:36

126 Views

In this tutorial, we will be discussing a program to understand extended integral types in C/C++.The data types in C are very loosely defined. Their range values changes on the basis of the compiler being 32 or 64 bit. To specify the compiler range you want to use in your program we use intN_t.Example Live Demo#include using namespace std; int main(){    uint8_t i; //mentioning the bit to be 8    i = 0;    cout

File Handling through C++ Classes

Ayush Gupta
Updated on 11-Dec-2024 19:20:31

1K+ Views

In this tutorial, we will be discussing a program to understand File Handling through C++ classes. What's File Handling? File handling is an important concept in programming, which allows a program to read from and write to files. C++ has built-in classes and functions for file handling, which is done using file stream classes that are part of the  library. The most common file stream classes in C++ are ofstream, ifstream, fstream. ofstream: This class is used for output file streams, where it allows the user to write data to files. ... Read More

Draw a line in C++ graphics

Ayush Gupta
Updated on 23-Mar-2020 08:30:09

6K+ Views

In this tutorial, we will be discussing a program to draw a line in C++ graphics.To implement different shapes and sizes, animations, graphics.h library is used in C++.Example#include int main(){    int gd = DETECT, gm;    initgraph(&gd, &gm, "");    line(150, 150, 450, 150);    line(150, 200, 450, 200);    line(150, 250, 450, 250);    getch();    closegraph();    return 0; }Output

Does C++ compiler create default constructor when we write our own?

Ayush Gupta
Updated on 23-Mar-2020 08:27:02

214 Views

In this tutorial, we will be discussing a program to understand if the C++ compiler creates a default constructor when we write our own.Generally, the C++ compiler uses the default constructor when no one is defined, but always uses the one defined by the user if any.Example Live Demo#include using namespace std; class myInteger{ private:    int value;    //other functions in class }; int main(){    myInteger I1;    getchar();    return 0; }OutputCompiles successfullyExample#include using namespace std; class myInteger{    private:       int value;    public:       myInteger(int v) //user-defined constructor    { value = ... Read More

Delete and free() in C++ Program

Ayush Gupta
Updated on 23-Mar-2020 08:24:21

159 Views

In this tutorial, we will be discussing a program to understand delete() and free() functions in C++.Both of these functions are primarily used for the same purpose i.e freeing up unused memory. The delete() operator is for the ones allocated using new() and free() for the ones allocated using malloc().Example#include #include int main(){    int x;    int *ptr1 = &x;    int *ptr2 = (int *)malloc(sizeof(int));    int *ptr3 = new int;    int *ptr4 = NULL;    //incorrect usage of delete    delete ptr1;    delete ptr2;    //correct usage of delete    delete ptr3;    delete ptr4;    getchar();    return 0; }

Different methods to reverse a string in C/C++

Ayush Gupta
Updated on 23-Mar-2020 08:22:23

3K+ Views

In this tutorial, we will be discussing a program to understand different methods to reverse a string in C/C++.ExampleUser-defined reverse() function − Live Demo#include using namespace std; //function to reverse given string void reverse_str(string& str){    int n = str.length();    for (int i = 0; i < n / 2; i++)       swap(str[i], str[n - i - 1]); } int main(){    string str = "tutorialspoint";    reverse_str(str);    cout

Default Arguments in C++

Ayush Gupta
Updated on 23-Mar-2020 08:18:52

1K+ Views

In this tutorial, we will be discussing a program to understand default arguments in C++.Default arguments are those which are provided to the called function in case the caller statement does provide any value for them.Example Live Demo#include using namespace std; //function defined with default arguments int sum(int x, int y, int z=0, int w=0){    return (x + y + z + w); } int main(){    cout

Customizing termination behavior for uncaught exception In C++

Ayush Gupta
Updated on 23-Mar-2020 08:17:02

337 Views

In this tutorial, we will be discussing a program to customize behavior for an uncaught exceptions in C++.Usually, the exception is handled by the try-catch block, but there are instances where there isn’t a matching catch block and the program just terminates. This terminate() function is modifiable as per user requirements.Example Live Demo#include #include using namespace std; //defining custom terminator void myhandler(){    cout

is_reference Template in C++

Sunidhi Bansal
Updated on 23-Mar-2020 07:59:22

110 Views

In this article we will be discussing the working, syntax and examples of std::is_reference template in C++ STL.is_reference is a template which comes under header file. This template is used to check whether the given type T is a reference type or not.This template is a combination of is_rvalue and is_lvalue and checks whether either if one is true, the result of is_reference will be also true.What is a reference in C++?A reference is an alias or another name of the already existing variable. A reference is different from pointer −As we cannot set a reference as null but ... Read More

Advertisements