SEBA Class 10 Computer Science Chapter 8 Pointers In C

Join Roy Library Telegram Groups

Hello Viewers Today’s We are going to Share With You, The Complete Syllabus of SEBA Class 10 Computer Science Chapter 8 Pointers In C Solutions in English in This Page. Are you a Student of (Secondary Education Board of Assam). SEBA Class 10 Computer Science Chapter 8 Pointers In C Notes. Which you Can Download PDF SEBA Class 10 Computer Science Chapter 8 Pointers In C Question Answer for free using direct Download Link Given Below in This Post.

SEBA Class 10 Computer Science Chapter 8 Pointers In C

We have Shared in This Post, SEBA Class 10 Computer Science Chapter 8 Pointers In C Textbook PDF Download for Free with you. SEBA Class 10 Computer Science Chapter 8 Pointers In C Solutions PDF. I Hope, you Liked The information About The SEBA Class 10 Computer Science Chapter 8 Pointers In C Book PDF. If you liked Class 10 Computer Science Notes Then Please Do Share this Post With your Friends as Well.

Pointers In C

TEXTUAL QUESTIONS AND ANSWERS

EXERCISE

1. How is a pointer variable different from a normal?

Ans. A pointer variable (or pointer in short) is basically the same as the other variables, which can store a piece of data. Unlike normal variable which stores a value (such as an int, a double, a char), a pointer stores a memory address.

Pointers must be declared before they can be used, just like a normal variable.

2. Why is dynamic memory allocation an efficient memory management technique?

Ans. Dynamic memory allocation is the process of assigning the memory space during the. execution time or the run time. Thus, we can always have exactly the amount of space required – no more, no less. So, dynamic memory allocation is an efficient memory management technique.

3. How many bytes are needed to store an int pointer variable? Is it the same for a char pointer variable?

Ans. To store an int pointer variable, 4 bytes is required.

Yes, char pointer variable also needs 4 bytes.

4. Write the output of the following code segment.

(a) int *ptr, x = 9:

ptr = &x;

print(“\ %d”, (*ptr)++);

Solution:

Output:

9

Solution:

Output:

9

10

Solution:

Output:

10

Solution:

Output:

A

Solution:

Output:

A

Solution:

Output:

B

Solution:

Output:

B

5. Write a C program to dynamically allocate memory for an array to store 10 integers and display the first 5 out of them.

Solution:

Code:

#include<stdio.h>
#include<stdlib.h>int main(){int *n;n = (int*)malloc(10*sizeof(int));printf(“\nEnter the numbers: “);for(int i = 0; i<10;i++){scanf(“%d”, (n+i));}printf(“\n Displaying the first 5 numbers: “);for(int i = 0; i<5; i++){printf(“%d\t”, *(n+i));}return 0;}

Output:

S.L No.CONTENTS
Chapter 1Introduction To Computer Network
Chapter 2Html5 And Css3
Chapter 3Database Part – II Mysql
Chapter 4Introduction To Loops
Chapter 5Nested Loops In C
Chapter 6Arrays In C
Chapter 7Functions In C
Chapter 8Pointers In C
Chapter 9Structure In C
Chapter 10An Introduction To Object Oriented Programming
Chapter 11Case Studies

6. Write a C program to dynamically allocate memory for an array to store runs scored by Virat Kohli in the last ten ODI cricket matches. Write a function to find the maximum one.

Solution:

Code:

#include<stdio.h>#include<stdlib.h>int main(){int *n, temp, large=0;n = (int*)malloc(10*sizeof(int));printf(“\nEnter the runs scored by Virat Kohli in last 10 ODI matches:”);for(int i=0; i<10;i++){scanf(“%d”, (n+i));}for(int i = 0; i<10; i++){for(int j=i+1; j<10; j++){if(*(n+i)>*(n+j)){temp = *(n+i):*(n+i) = *(n+j):*(n+j) = temp;}}printf(“\n The maximum run scored by Virat Kohli is: %d”, “(n+9));return 0;}

Output:

7. Write a C program and define a function that takes the length of your name as an input parameter and then allocates memory dynamically to store your name. Write another function to display the name.

Solution:

Code:

#include <stdio.h>#include<stdlib.h>int main(){char *str,str=(char*)malloc(20*sizeof(char)):printf(“Enter your name: “);gets(str);printf(“\nEntered name is: “);while(*str!=’\0′)printf(“%c”,*str++);return 0;}

Output:

8. Write a C program to store some integer variables in an array. Then write functions to the following:

(a) To calculate the number of even numbers in the array.

(b) To dynamically allocate memory to a new array to store only the even numbers.

(c) To copy the even numbers from the first array to the second one.

Solution:

Code:

#include <stdio.h>#include<stdlib.h>int main(){int n[10];int *ptr;ptr=(int*)malloc(10*sizeof(int));printf(“Enter the elements of array: “);for(int i=0; i<10; i++){scanf(“%d”, &n[i]);}printf(“\n Displaying the even numbers in the second array :\n”);for(int i=0;i<10;i++){if(n[i] % 2 == 0){*(ptr+i)=n[i];printf(“%d\t”,*(ptr+i));}}return 0;}

Output:

9. Write a C program to store some integer variables in an array. Then write functions to do the following:

(a) To calculate the number of non-zero elements that are divisible by 3.

(b) To dynamically allocate to store only those elements.

(c) To copy the selected elements from the first array to the second one.

(d) To calculate the summation of these elements.

Solution:

Code:

#include <stdio.h>#include<stdlib.h>int main(){int n[10], count=0, sum=0;int *ptr;ptr=(int*)malloc(10*sizeof(int));printf(“Enter the elements of array: “);for(int i=0; i<10; i++){scanf(“%d”, &n[i]);}for(int i=0;i<10;i++){if(n[i] % 3 == 0){*(ptr+i) = n[i];count++;printf(“%d\t”, *(ptr+i));sum = sum + *(ptr+i);}}printf(“\n Number of non-zero elements that are divisible by 3: %d”, count);printf(“\n Sum of the numbers is: %d”, sum);return 0;}

Output:

ADDITIONAL QUESTIONS AND ANSWERS

1. What is pointer in C?

Ans. The pointer in C language is a variable which stores the address of another variable.

2. Why are pointers in C useful?

Ans. C uses pointers to create dynamic data structures—data structures built up from blocks of memory allocated from the heap at run-time. C uses pointers to handle variable parameters passed to functions.

3. What is difference between array and pointer?

Ans. Array in C is used to store elements of same types whereas Pointers are address variables which stores the address of a variable.

4. What is dynamic memory allocation?

Ans. In C, dynamic memory is allocated from the heap using some standard library functions. In other words, it enables the C programmers to allocate memory at runtime.

5. What is malloc()?

Ans. The malloc() function is defined in the header <stdlib. h> and allows us to allocate memory during run-time.

6. What does sizeof( ) mean?

Ans. It returns the size of a variable. It can be applied to any data type, float type, pointer type variables. When sizeof() is used with the data types, it simply returns the amount of memory allocated to that data type. In other words, The sizeof( ) operator in C is used to find the memory its operand occupies in the computer’s memory.

7. What is * operator?

Ans. The Operator is also known as Value at address operator.

8. What does *ptr denote in the following program?

int a = 10;

int *ptr;

ptr=&a;

Ans. ptr would give the value of a.

9. What is the size of char pointer?

Ans. The size of character pointer is 4 bytes for 32 bit processor and 8 bytes for 64 bit processor.

10. What is the size of int pointer?

Ans. The size of int pointer is 4 bytes for 32 bit processor and 8 bytes for 64 bit processor.

Leave a Reply

error: Content is protected !!
Scroll to Top