C programming 1st Sem Solution 2025

Uncategorized

17. Write a program to print the multiplication table up to 10 of a given integer.

 

18. Write a program to find the second greatest element in an integer array.

 

19. Write a program to create a structure named ‘ Book’ with data members, bookname, author and price. List the name of those books having price > 500.

 

20.Write a program to add two matrices.

 

21. Why do we need storage class? List some graphics functions. How do you pass and return pointer in function? Illustrate with an example.

storage classes define the scope, lifetime, and initial value of a variable, as well as its storage location (memory or CPU register). They determine how and where a variable will be stored and for how long it will exist.

common graphics functions include:

  • initgraph(): Initializes the graphics mode and drivers.
  • closegraph(): Closes the graphics mode.
  • setcolor(): Sets the current drawing color.
  • setfillstyle(): Sets the fill pattern and color for shapes.
  • line(): Draws a line between two specified points.
  • circle(): Draws a circle with a given center and radius.
  • rectangle(): Draws a rectangle with specified top-left and bottom-right corners.
  • arc(): Draws an arc.

 

 

Passing a Pointer to a Function (Call by Reference):

When you pass a pointer to a function, you are essentially passing the memory address of a variable. This allows the function to directly access and modify the original variable in the calling function’s scope. This is known as “call by reference.”

  • Syntax: The function parameter type will be a pointer (e.g., int *ptr).
  • Call: You pass the address of the variable using the address-of operator (&) (e.g., &myVariable).

Returning a Pointer from a Function:

A function can return a pointer. This means the function returns a memory address. You must be careful when returning pointers:

  • Do NOT return pointers to local (automatic) variables: Local variables are allocated on the stack and are destroyed when the function exits. Returning a pointer to such a variable results in a “dangling pointer,” which points to deallocated memory, leading to undefined behavior.

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *