• Post Reply Bookmark Topic Watch Topic
  • New Topic

Array Questions  RSS feed

 
Danish Shaukat
Ranch Hand
Posts: 341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I was asked by someone to give comments on some java statements. The statements and my comments are as under. I thought well before answering and also verified by making a small program. But I was told that I was wrong.

I can�t figure out which comment is incorrect.

No 1:
--------
char string [50];
This is an invalid array declaration. You will get a compiler error.

No: 2
--------
char *arry; arry = new char[256];
These are two statements. I will break them up.

char *arry;
*arry is an invalid identifier. You will get compiler error.

arry=new char[256];

Since arry has not been declared anywhere so again the code will not
compile.
If arry had been declared as an array of type char, then this statement
would have created a char array of length 256. But this is not the case.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No 1: This is how you declare an array of 50 characters, in C or C++;

No 2: This is how you declare a character pointer, and then allocate an array of 256 characters from the heap, in C++;

My comment would be... get a C++ compiler and these instructions will compile fine...

Henry
[ May 06, 2005: Message edited by: Henry Wong ]
 
Giovanni De Stefano
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mmmm...let's see...I thought the name of this community was JAVARANCH...WHAT'S GOING ON HERE???
I can tolerate C (I actually like it!) BUT I CANNOT STAND AT C++!!!

Please moderators, remove this topic!!!

Giovanni
 
Danish Shaukat
Ranch Hand
Posts: 341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Giovanni De Stefano:
Mmmm...let's see...I thought the name of this community was JAVARANCH...WHAT'S GOING ON HERE???
I can tolerate C (I actually like it!) BUT I CANNOT STAND AT C++!!!

Please moderators, remove this topic!!!

Giovanni


If you read my post carefully, I was to give comments on "java statements". I did not know this was C++. This was weird java code indeed.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!