Character arrays and pointer in C plus plus programming language

Character arrays and pointer in C plus plus programming language

Instructor-svgAl-Mamun Sarkar
Apr 03 , 2020

Character arrays and pointer in C plus plus programming language. The following code shows the use of char array and pointer in C plus plus Programming Language.

 

Code:

#include<iostream>
#include<string.h>

using namespace std;

int main()
{
    char c[50];
    c[0]= 'M';
    c[1]= 'a';
    c[2]= 'm';
    c[3]= 'u';
    c[4]= 'n';
    c[5]= '\0';

    char name[] = "Mamun sarkar";
    char *p = name;

    cout << "Name is : " << c << endl;
    cout << "Name is via pointer : " << p << endl;
    cout << "Name is : " << name << endl;
    cout << "Size is : " << sizeof(name) << endl;
    cout << "Length is : " << strlen(name) << endl;

    return 0;
}

 

Output:

Name is : Mamun
Name is via pointer : Mamun sarkar
Name is : Mamun sarkar
Size is : 13
Length is : 12

 

  • Share On:
  • fb
  • twitter
  • pinterest
  • instagram