Question: In LINUX by using c++ or c language 1) Explain the result for following code x='a'; y=98; printf(%d %c %d %c , x, x, y,

In LINUX by using c++ or c language

1) Explain the result for following code

x='a'; y=98;

printf("%d %c %d %c ", x, x, y, y);

char * x1 = "hello";

printf("%s %p %s %p ", x1, x1, "hello", "hello");

2) How to declare a character array with 128 rooms. Store 0 to 127 in this array and print the corresponding character for each ascii code in the array.

3) Write a program that keeps reading a string, displaying its length, making a copy of it, and checking whether it is "hello". If the input string is "hello", the program stops.

Enter a string

hi

You entered hi. length=2

After making a copy. x:hi y:hi

No it is not hello

Enter a string

hello

You entered hello. length=5

After making a copy. x:hello y:hello

Yes it is hello

4) A string constant such as "hello" is an address. Explain the result of following code.

char *x, *y, *z;

x="hello"; y="hi"; z="bye";

printf("%s %s %s ", x, y, z);

printf("%p %p %p ", x, y, z);

5) Try below and explain why we have an error.

char x[20];

strcpy(x, "hello"); // this is ok

x="hello"; // this is an error

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!