Showing posts with label operator. Show all posts
Showing posts with label operator. Show all posts

Sunday, August 21, 2016

String in Java

Strings in Java

1. int n;
char chr;
String st1=”Rakesh Roshan”;
n=st1.indexOf(‘e’);
chr=st1.charAt(5);

what will be the value of n and chr?

2. int n;
String str1=”Rakesh”;
String str2=”Roshan”;
n=str1.compareTo(st2);

what will be the value of n ?

Different way to access array elements

Do you know there are many ways to access the elements of array.
int Num[10];
for(int i=0;i<10;i++)
    printf("%d%d%d%d",Num[i],i[Num],*(Num+i),*(i+Num));
Here all the format will give the same result that is every element of Array.

Saturday, August 20, 2016

What will be the output of -1<<4 in C language?
Ans: The binary equivalent of -1 in 2 Byte is 1111 1111 1111 1111.
So after 4 left shift the result will be 1111 1111 1111 0000.
Hence the output will be fff0  in Hexadecimal format.

This question is very common for the placement exams of various company.