#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 to show that word has ended
}
char* example = "Lorem ipsum dolor sit amet";
int length = strlen(example);
std::cout << length << '
'; // 26
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.
const char* Coffee = "Nescafe";
for(int i = 0; i < strlen(Coffee); i++)
{
std::cout << Coffee[i] << "
";
}
Code Example |
---|
Cpp :: random number of 0 or 1 c++ |
Cpp :: how print fload wiht 2 decimal in c++ |
Cpp :: number of lines in c++ files |
Cpp :: how to make a list in c++ |
Cpp :: c++ 2d vector assign value |
Cpp :: Write C++ program to sort an array in ascending order |
Cpp :: c++ typeid |
Cpp :: find in string c++ |
Cpp :: c++ create multidimensional vector |
Cpp :: find primes in a range in c++ |
Cpp :: push_back struct c++ |
Cpp :: c++ inline in .cpp and not in header |
Cpp :: double to int c++ |
Cpp :: change int to string c++ |
Cpp :: casting c++ |
Cpp :: read and write file in c++ |
Cpp :: size of array |
Cpp :: set clear c++ |
Cpp :: c++ cout format |
Cpp :: back() in c++ |
Cpp :: filling 2d array with 0 c++ |
Cpp :: how to find last character of string in c++ |
Cpp :: 3d projection onto 2d plane algorithm |
Cpp :: panic: assignment to entry in nil map |
Cpp :: cpp getter as const |
Cpp :: c++ contains |
Cpp :: how many months have 31 days |
Cpp :: dynamic allocation c++ |
Cpp :: cuda shared variable |
Cpp :: std::count() in C++ STL |