strings

#include<iostream.h>
void main()
{
char *str []={"lovely","hakeem"};
cout<<sizeof(str);
}

its size is 8;can any one tell me how?????
is str is pointer here?????
tnx
No, str is a pointer array with two elements.
If sizeof(char*) is 4 on your system, then str's size will be 8.

By the way, line 1, 2, 4 and 5 are not valid C++ and won't compile with a recent compiler.

This is a correct version of the program:
1
2
3
4
5
6
7
8
#include <iostream>
using namespace std;

int main()
{
  const char* str[]={"lovely","hakeem"};
  cout << sizeof(str);
}
Since you're using C++ just use std::string. It's very awesome.
Topic archived. No new replies allowed.