• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Arrays

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
char a [] = "ABCD\r\n" ; How many elements are there in array?

Answer is 7...but according to me it should be 6 b'coz /r is carriage return and /n is new line, does arrays also have one more /n as like Strings?
 
Rahul Bajaj
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also which function will get called?


int abs(int n);
long abs(long n);
double abs(double n);
float abs(float n);
int main()
{
cout << abs(-10L);
return 0;
}


according to me it should be long abs(long) but its incorrect...according to answers of mock exam.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your first example won't compile; you can't assign a String to an array variable. Maybe you meant

char[] = "ABCD\r\n".toCharArray()?

In that case, the answer is six. You'll have to tell us where you read that there should be seven characters. I can't imagine what you mean with regards to Strings having "one more '\n'" : nothing of the sort is true.

As to your second example: your code is much closer to C++ than to Java. A Java version might look like:



This program prints 2, as you'd expect. Unless you're reading it wrong, I think the best thing to do with the mock exam you're using is to line a birdcage with it, and find some other references.

I'm going to move this to SCJP, where this sort of question is on-topic.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic