Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions