0% found this document useful (0 votes)
28 views4 pages

Practice Problems

The document contains a series of C programming practice problems that cover various concepts such as pointer manipulation, memory addresses, data types sizes, and function calls by value and reference. It includes code snippets that demonstrate how to swap values and manage integer variables using pointers. Additionally, it outlines a task to write a program that sorts three integers and places them in specific variables based on their size.

Uploaded by

krishna km
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views4 pages

Practice Problems

The document contains a series of C programming practice problems that cover various concepts such as pointer manipulation, memory addresses, data types sizes, and function calls by value and reference. It includes code snippets that demonstrate how to swap values and manage integer variables using pointers. Additionally, it outlines a task to write a program that sorts three integers and places them in specific variables based on their size.

Uploaded by

krishna km
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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