char in c

Posted under C++ Course On By mohammed.mutawe

char in c

It is denoted in the C++ language , the definition of the variable char, which is a reserved space dedicated to char within C++ and can be used a lot during writing large variables and has some uses also different inside String classes.

 

setw function

It is a function that is able to choose one sentence from among the letters. In our example, that function will choose the first print sentence, but the word length does not exceed 20 char.

 

Avoid stack

In defining any variable of type char , it is always preferable to subtract the total length of the char from one value because there are no problems or heap overflow.

 

Example

Please, for a better understanding of character variables, copy the following code into your code editor.

#include<iostream>
#include<iomanip>
using namespace std;

int main() {
    const int max = 20;
    char str[max - 1];     //because null value of character

    cout << "Enter An String "; cin >> setw(max) >> str;
    cout << "You Entered \n" << str;

    

    return 0;
}

 

Leave a comment

Your email address will not be published. Required fields are marked *