0% found this document useful (0 votes)
6 views

Practice Problems

Uploaded by

krishna km
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Practice Problems

Uploaded by

krishna km
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Practice problems:

1.

#include <stdio.h>

main()

int a, b;

int c = 5;

int *p;

a = 4 * (c + 5) ;

p = &c;

b = 4 * (*p + 5) ;

printf (“a=%d b=%d \n”, a, b) ;

2.

#include <stdio.h>

main()

int x, y;

int *ptr;

x = 10 ;

ptr = &x ;

y = *ptr ;

printf (“%d is stored in location %u \n”, x, &x) ;


printf (“%d is stored in location %u \n”, *&x, &x) ;

printf (“%d is stored in location %u \n”, *ptr, ptr) ;

printf (“%d is stored in location %u \n”, y, &*ptr) ;

printf (“%u is stored in location %u \n”, ptr, &ptr) ;

printf (“%d is stored in location %u \n”, y, &y) ;

*ptr = 25;

printf (“\nNow x = %d \n”, x);

3.

#include <stdio.h>

main()

printf (“Number of bytes occupied by int is %d \n”, sizeof(int));

printf (“Number of bytes occupied by float is %d \n”, sizeof(float));

printf (“Number of bytes occupied by double is %d \n”, sizeof(double));

printf (“Number of bytes occupied by char is %d \n”, sizeof(char));

4. Call by value:

#include <stdio.h>

main()

int a, b;

a = 5 ; b = 20 ;

swap (a, b) ;
printf (“\n a = %d, b = %d”, a, b);

void swap (int x, int y)

int t ;

t=x;

x=y;

y=t;

5. Call by reference:

#include <stdio.h>

main()

int a, b;

a = 5 ; b = 20 ;

swap (&a, &b) ;

printf (“\n a = %d, b = %d”, a, b);

void swap (int *x, int *y)

int t ;

t = *x ;

*x = *y ;

*y = t ;
}

6. Write a program with swap function that does the following:

Read in three integers x, y and z

Put smallest in x

Swap x, y if necessary; then swap x, z if necessary.

Put second smallest in y

Swap y, z if necessary

You might also like