Showing posts with label strings. Show all posts
Showing posts with label strings. Show all posts

Tuesday, May 19, 2009

You have a program containing the following statements:

#define ARRAYSIZE 20
char str[ARRAYSIZE]="Test string";
strcat(str, 'z');

When you run the program, it produces a segmentation fault.

Referring to the above scenario, how do you resolve the problem?
Choice a : Use malloc to dynamically allocate memory, rather than using a fixed array.
Choice b : Change 'z' to 'z\0'
Choice c : Change ARRAYSIZE to 21.
Choice d : Change 'z' to "z"
Choice e : Change strcat to strncat and specify a size of 1.

You are looping through a set of results from an SQL database query,

Looking for a specific sequence of entries. Once the sequence of entries is found, you want to stop the loop and continue the program at the statement following the loop

Given the scenario described above, which line of code do you use?

Choice a : if (strcmp (DBSequence, "SEQUENCE")==0) continue;
Choice b : if (strcmp (DBSequence, "SEQUENCE")=0) break;
Choice c : if (strcmp (DBSequence, "SEQUENCE")==0) break;
Choice d : if (strcmp (DBSequence, "SEQUENCE")==0) return 0;
Choice e : if (strcmp (DBSequence, "SEQUENCE")==0) exit;

Monday, March 9, 2009

What's the difference between these three declarations?

char *a = "abc";
char b[] = "abc";
char c[3] = "abc";

Answer:The first declares a pointer-to-char, initialized to point to a four-character array somewhere in (possibly read-only) memory containing the four characters a b c \0. The second declares an array (a writable array) of 4 characters, initially containing the characters a b c \0. The third declares an array of 3 characters, initially containing a b c. (The third array is therefore not an immediately valid string.)

Monday, January 26, 2009

State o/p

#include
int main()
{
printf("%d",-16["WHAT A PLAYER WHAT A PLAYER SLUMDOG!!!"]);
return 0;
}
A. Error
B. GARBAGE
C. 65
D. none of the above

Wednesday, January 21, 2009

Find the correct output

void main()
{
char a[]=”rama”;
char b[]=a;
printf (“%d %s”, sizeof (b),b);
}

(a) 5 rama

(b) 4 rama

(c) 5 r

(d) None of these, some other reason