Class 10 Computer Science Chapter 8 Pointers In C Question Answer, SEBA Class 10 Computer Science Solutions, NCERT Class 10 Computer Science Chapter 8 Pointers In C to each chapter is provided in the list so that you can easily browse throughout different chapters SCERT Class 10 Computer Science Chapter 8 Pointers In C and select needs one.
Class 10 Computer Science Chapter 8 Pointers In C
Also, you can read the SCERT book online in these sections Solutions by Expert Teachers as per SCERT (CBSE) Book guidelines. NCERT Solution of Class 10 Computer Science Chapter 8 Pointers In C is part of AHSEC All Subject Solutions. Here we have given Class 10 Computer Science Chapter 8 Pointers In C Notes for All Subjects, You can practice these here in Class 10 Computer Science.
POINTERS IN C
Chapter – 8
COMPUTER SCIENCE
Key Terms (Basic Concepts)
● Pointer: The pointer in C language is a variable which stores the address of another variable.
● Dynamic: When the memory allocation is done at the execution or run time, then it is called dynamic memory allocation.
● Static: When the allocation of memory performs at the compile time, then it is known as static memory.
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.

Solution:
Output:
9

Solution:
Output:
9
10
Solution:
Output:
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(“\n Enter 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:

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(“\n Enter 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(“\n Entered 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 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 is 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 simple 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.