unor
0
Q:

how to find the size of a character array in c++

#include <iostream>

using namespace std;

int main()
{
    char arr[] = "grepper";
    cout << sizeof(arr) << endl;
    return 0;
    //    keep it in mind that character arrays have length of one more than your characters because last one is for \0 to show that word has ended
}
-3
Instead of sizeof() for finding the length of strings or character 
arrays, just use strlen(string_name) with the header file
#include <cstring>   
it's easier.
0
sizeof vs strlen()

Type: Sizeof operator is a unary operator whereas strlen() 
    is a predefined function in C.
Data types supported: Sizeof gives actual size of any type of 
	data (allocated) in bytes (including the null values) whereas 
    get the length of an array of chars/string.
Evaluation size: sizeof() is a compile-time expression giving you 
	the size of a type or a variable’s type. It doesn’t care about 
    the value of the variable. Strlen on the other hand, gives you 
    the length of a C-style NULL-terminated string.
Summary: The two are almost different concepts and used for 
  	different purposes.
0

New to Communities?

Join the community