Have a look at the following piece of code and state and explain the output.   #include   int main() {             // your code goes here             int a = 10, b = 20;             int *p = &a;             *p = b;             printf("%d", a);             return 0; }   ii) Have a look at the following piece of code and state and explain the output.   #include   void fun(int *a, int *b){             a = b;             b = a; }   int main(void) {             // your code goes here             int a = 10, b = 20;             fun(&a, &b);             printf("a: %d\n", a);             printf("b: %d\n", b);             return 0; }   iii) Have a look at the following piece of code and state and explain the output.   #include   int main() {             // your code goes here             char s[20] = "abc";             if(strcmp(strcpy(s, "def"), "abcdef"))                         printf("Hi");             else                         printf("Bye");             return 0; }

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter7: User-defined Simple Data Types, Namespaces, And The String Type
Section: Chapter Questions
Problem 1TF
icon
Related questions
Question

 i) Have a look at the following piece of code and state and explain the output.

 

#include <stdio.h>

 

int main() {

            // your code goes here

            int a = 10, b = 20;

            int *p = &a;

            *p = b;

            printf("%d", a);

            return 0;

}

 

ii) Have a look at the following piece of code and state and explain the output.

 

#include <stdio.h>

 

void fun(int *a, int *b){

            a = b;

            b = a;

}

 

int main(void) {

            // your code goes here

            int a = 10, b = 20;

            fun(&a, &b);

            printf("a: %d\n", a);

            printf("b: %d\n", b);

            return 0;

}

 

iii) Have a look at the following piece of code and state and explain the output.

 

#include <stdio.h>

 

int main() {

            // your code goes here

            char s[20] = "abc";

            if(strcmp(strcpy(s, "def"), "abcdef"))

                        printf("Hi");

            else

                        printf("Bye");

            return 0;

}

 

 

iv) Have a look at the following piece of code and state and explain the output.

 

#include <stdio.h>

 

int main() {

            // your code goes here

            char s[20] = "abcdef";

            strcpy(s, "\0");

            printf("%d", strlen(s));

            return 0;

}

 

 

 

 

v) Have a look at the following piece of code and state and explain the output.

 

#include <stdio.h>

 

int main() {

            // your code goes here

            char *s = "abcdef";

            *(s + 2) = '\0';

            printf("%d", s);

            return 0;

}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Datatypes
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning