Pointers in C | Chapter 8 |  Class 10 Computer Science 571(NCERT) Question and Answer | Class 10 Computer Science 571(NCERT) Question and Answer Solutions English Medium |


Pointers in C

Chapter 8



Exercise


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

(āĻāϟা āĻĒāχāĻŖ্āϟাā§° āĻ­েā§°িāϝ়েāĻŦāϞ āĻāϟা āϏাāϧাā§°āĻŖ āĻ­েā§°িāϝ়েāĻŦāϞ⧰ āĻĒā§°া āĻ•েāύেāĻ•ৈ āĻĒৃāĻĨāĻ•?)

 Ans: pointer variables (or pointers for short) are essentially the same as other variables, which can store a piece of data. Unlike common variables that store a value (e.g., int, double, mister), the cursor stores a memory address. Cursors must be declared before they are used as normal variables.

(āĻĒāχāĻŖ্āϟাā§° āĻ­েā§°িāϝ়েāĻŦāϞ (āĻŦা āϚāĻŽুāĻ•ৈ āĻĒāχāĻŖ্āϟাā§°) āĻŽূāϞāϤঃ āφāύ āϚāϞāϕ⧰ āĻĻā§°ে āĻāĻ•ে, āϝি āĻĄাāϟাā§° āϟুāĻ•ুā§°া āĻāϟা āϏংā§°āĻ•্āώāĻŖ āϕ⧰িāĻŦ āĻĒাā§°ে। āĻŽূāϞ্āϝ āĻāϟা āϏংā§°āĻ•্āώāĻŖ āϕ⧰া āϏাāϧাā§°āĻŖ āϚāϞāϕ⧰ āĻŦিāĻĒā§°ীāϤে (āϝেāύে, āχāĻŖ্āϟ, āĻĄাāĻŦāϞ, āĻŽিāώ্āϟাā§°), āĻ•াā§°্āϚাā§°ে āĻŽেāĻŽ'ā§°ী āĻ িāĻ•āύা āĻāϟা āϏংā§°āĻ•্āώāĻŖ āϕ⧰ে। āĻ•াā§°্āϚাā§°āĻŦোā§° āϏাāϧাā§°āĻŖ āϚāϞāĻ• āĻšিāϚাāĻĒে āĻŦ্āĻ¯ā§ąāĻšাā§° āϕ⧰াā§° āφāĻ—āϤে āϘোāώāĻŖা āϕ⧰িāĻŦ āϞাāĻ—িāĻŦ।)

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

(āĻĄাāχāύাāĻŽিāĻ• āĻŽেāĻŽā§°ি āφāĻŦāĻŖ্āϟāύ āĻ•িāϝ় āĻāϟা āĻĻāĻ•্āώ āĻŽেāĻŽā§°ি āĻŦ্āĻ¯ā§ąāϏ্āĻĨাāĻĒāύা āĻ•ৌāĻļāϞ?)

Ans: Dynamic memory allocation is a computer programming technique used to manage memory more efficiently. It allows a program to allocate memory blocks, make them free, and reassign them during program editing

(āĻĄাāχāύাāĻŽিāĻ• āĻŽেāĻŽā§°ি āĻ†ā§ąāĻŖ্āϟāύ āĻšৈāĻ›ে āĻŽেāĻŽā§°ি āĻ…āϧিāĻ• āĻĻāĻ•্āώāϤাā§°ে āĻĒā§°িāϚাāϞāύা āϕ⧰িāĻŦāϞৈ āĻŦ্āĻ¯ā§ąāĻšাā§° āϕ⧰া āĻāĻ• āĻ•āĻŽ্āĻĒিāωāϟাā§° āĻĒ্ā§°āĻ—্ā§°াāĻŽিং āĻ•ৌāĻļāϞ। āχ āĻĒ্ā§°'āĻ—্ā§°াāĻŽ āĻāϟাāĻ• āĻŽেāĻŽ'ā§°ী āĻŦ্āϞāĻ• āĻ†ā§ąāĻŖ্āϟāύ āϕ⧰িāĻŦāϞৈ, āϏেāχāĻŦোā§° āĻŦিāύাāĻŽূāϞীāϝ়া āϕ⧰িāĻŦāϞৈ āφ⧰ু āĻĒ্ā§°'āĻ—্ā§°াāĻŽ āϏāĻŽ্āĻĒাāĻĻāύাā§° āϏāĻŽāϝ়āϤ āϏেāχāĻŦোā§° āĻĒুāύ⧰ āĻ†ā§ąāĻŖ্āϟāύ āϕ⧰িāĻŦāϞৈ āĻ…āύুāĻŽāϤি āĻĻিāϝ়ে)

3. How many bytes are needed to store an int pointer variable? Is it the same for a char pointer variable? Write a simple C program to explain your answer.

(āĻāϟা āχāĻŖ্āϟ āĻĒāχāĻŖ্āϟাā§° āϚāϞāĻ• āϏংā§°āĻ•্āώāĻŖ āϕ⧰িāĻŦāϞৈ āĻ•িāĻŽাāύāϟা āĻŦাāχāϟ⧰ āĻĒ্ā§°āϝ়োāϜāύ? āϚাā§° āĻĒāχāĻŖ্āϟাā§° āϚāϞāϕ⧰ āĻŦাāĻŦে āĻāχāϟো āĻāĻ•ে āύেāĻ•ি? āφāĻĒোāύাā§° āωāϤ্āϤ⧰ āĻŦুāϜাāĻŦāϞৈ āĻāϟা āϏ⧰āϞ āϚি āĻĒ্ā§°'āĻ—্ā§°াāĻŽ āϞিāĻ–āĻ•।)

Ans: The size of the cursor variables is the same for each data type. It will be 8 bytes for the 64-bit processor, 4 bytes for the 32-bit processor, 2 bytes for the 16-bit processor.

(āĻĒ্ā§°āϤিāϟো āĻĄাāϟা āĻĒ্ā§°āĻ•াā§°ā§° āĻŦাāĻŦে āĻ•াā§°্āϚ⧰ āϚāϞāϕ⧰ āφāĻ•াā§° āĻāĻ•ে। āχ 64-āĻŦিāϟ āĻĒ্ā§°āϚেāϛ⧰⧰ āĻŦাāĻŦে 8 āĻŦাāχāϟ, 32-āĻŦিāϟ āĻĒ্ā§°āϚেāϛ⧰⧰ āĻŦাāĻŦে 4 āĻŦাāχāϟ, 16-āĻŦিāϟ āĻĒ্ā§°āϚেāϛ⧰⧰ āĻŦাāĻŦে 2 āĻŦাāχāϟ āĻš'āĻŦ।)

4. Write the output of the following code segment.

(āύিāĻŽ্āύāϞিāĻ–িāϤ āĻ•োāĻĄ āĻ–āĻŖ্āĻĄā§° āφāωāϟāĻĒুāϟ āϞিāĻ–āĻ•।)

a.










Ans: Output was 9 


b.











Ans: Output was 9 and 10

C.











Ans: Output was 10


d. 








Ans: Output was 10


e. 







Ans: Output was A


f. 







Ans: Output was B

g. 








Ans: Output was 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.

( 10 āϟা āχāĻŖ্āϟেāĻ—াā§° āϏংā§°āĻ•্āώāĻŖ āϕ⧰িāĻŦāϞৈ āφ⧰ু āϏেāχāĻŦোā§°ā§° āĻ­িāϤ⧰āϤ āĻĒ্ā§°āĻĨāĻŽ 5 āϟা āĻĒ্ā§°āĻĻā§°্āĻļāύ āϕ⧰িāĻŦāϞৈ āĻā§°েāĻāϟাā§° āĻŦাāĻŦে āĻ—āϤিāĻļীāϞāĻ­াā§ąে āĻŽেāĻŽ'ā§°ী āĻ†ā§ąāĻŖ্āϟāύ āϕ⧰িāĻŦāϞৈ āĻāϟা āϚি āĻĒ্ā§°'āĻ—্ā§°াāĻŽ āϞিāĻ–āĻ•।)

Ans: 


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.

(āϝোā§ąা āĻĻāĻšāĻ–āύ āĻāĻĻিāύীāϝ়া āĻ•্ā§°িāĻ•েāϟ āĻ–েāϞāϤ āĻŦিā§°াāϟ āĻ•োāĻšāϞীāϝ়ে āϏংāĻ—্ā§°āĻš āϕ⧰া ā§°াāĻŖ āϏংā§°āĻ•্āώāĻŖ āϕ⧰িāĻŦāϞৈ āĻ—āϤিāĻļীāϞāĻ­াā§ąে āĻŽেāĻŽā§°ি āĻ†ā§ąāĻŖ্āϟāύ āϕ⧰িāĻŦāϞৈ āĻāϟা āϚি āĻĒ্ā§°āĻ—্ā§°াāĻŽ āϞিāĻ–āĻ•। āϏ⧰্āĻŦাāϧিāĻ• āĻāϟা āĻŦিāϚাā§°িāĻŦāϞৈ āĻĢাংāϚāύ āĻāϟা āϞিāĻ–āĻ•।)
Ans: 

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.

āĻāϟা āϚি āĻĒ্ā§°'āĻ—্ā§°াāĻŽ āϞিāĻ–āĻ• āφ⧰ু āĻāϟা āĻĢাংāϚāύ āύিā§°্āϧাā§°āĻŖ āϕ⧰āĻ• āϝি āφāĻĒোāύাā§° āύাāĻŽā§° āĻĻৈā§°্āϘ্āϝāĻ• āχāύāĻĒুāϟ āĻĒ্ā§°াāϚāϞ āĻšিāϚাāĻĒে āϞāϝ় āφ⧰ু āϤাā§° āĻĒিāĻ›āϤ āφāĻĒোāύাā§° āύাāĻŽ āϏংā§°āĻ•্āώāĻŖ āϕ⧰িāĻŦāϞৈ āĻ—āϤিāĻļীāϞāĻ­াā§ąে āĻŽেāĻŽā§°ি āĻ†ā§ąāĻŖ্āϟāύ āϕ⧰ে। āύাāĻŽāϟো āĻĒ্ā§°āĻĻā§°্āĻļāύ āϕ⧰িāĻŦāϞৈ āφāύ āĻāϟা āĻĢাংāϚāύ āϞিāĻ–āĻ•।

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

āĻāϟাāϤ āĻ•িāĻ›ুāĻŽাāύ āχāĻŖ্āϟিāĻ—াā§° āϚāϞāĻ• āϏংā§°āĻ•্āώāĻŖ āϕ⧰িāĻŦāϞৈ āĻāϟা āϚি āĻĒ্ā§°'āĻ—্ā§°াāĻŽ āϞিāĻ–āĻ•। āϤাā§° āĻĒিāĻ›āϤ āύিāĻŽ্āύāϞিāĻ–িāϤāĻŦোā§°āϞৈ āĻĢাংāϚāύāĻŦোā§° āϞিāĻ–āĻ•।

1. To calculate the number of even numbers in the array.

(āĻā§°েāϤ āϏāĻŽাāύ āϏংāĻ–্āϝাā§° āϏংāĻ–্āϝা āĻ—āĻŖāύা āϕ⧰িāĻŦāϞৈ।)

Ans: 

2. To dynamically allocate memory to a new array to store only the even numbers.

 āĻ•েā§ąāϞ āϏāĻŽাāύ āϏংāĻ–্āϝাāĻŦোā§° āϏংā§°āĻ•্āώāĻŖ āϕ⧰িāĻŦāϞৈ āύāϤুāύ āĻā§°েāĻāϟাāϤ āĻ—āϤিāĻļীāϞāĻ­াā§ąে āĻŽেāĻŽ'ā§°ী āĻ†ā§ąāĻŖ্āϟāύ āϕ⧰িāĻŦāϞৈ।


3. To copy the even numbers from the first array to the second one.

āĻĒ্ā§°āĻĨāĻŽ āĻā§°েā§° āĻĒā§°া āĻĻ্āĻŦিāϤীāϝ়āϟোāϞৈ āϏāĻŽাāύ āύāĻŽ্āĻŦā§°āĻŦোā§° āĻĒ্ā§°āϤিāϞিāĻĒি āϕ⧰িāĻŦāϞৈ।

Sample run:


First array


Second array




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

āĻā§°েāĻāϟাāϤ āĻ•িāĻ›ুāĻŽাāύ āχāĻŖ্āϟিāĻ—াā§° āϚāϞāĻ• āϏংā§°āĻ•্āώāĻŖ āϕ⧰িāĻŦāϞৈ āĻāϟা āϚি āĻĒ্ā§°'āĻ—্ā§°াāĻŽ āϞিāĻ–āĻ•। āϤাā§° āĻĒিāĻ›āϤ āύিāĻŽ্āύāϞিāĻ–িāϤāĻŦোā§°āϞৈ āĻĢাংāϚāύāĻŦোā§° āϞিāĻ–āĻ•।

1. To calculate the number of non-zero elements that are divisible by 3.

3-ā§° āĻĻ্āĻŦাā§°া āĻŦিāĻ­াāϜ্āϝ āύোāĻšোā§ąা āĻ…-āĻļূāύ্āϝ āωāĻĒাāĻĻাāύ⧰ āϏংāĻ–্āϝা āĻ—āĻŖāύা āϕ⧰িāĻŦāϞৈ।

2. To dynamically allocate memory to a new array to store only those elements.

 āĻ•েā§ąāϞ āϏেāχ āωāĻĒাāĻĻাāύāĻŦোā§° āϏংā§°āĻ•্āώāĻŖ āϕ⧰িāĻŦāϞৈ āύāϤুāύ āĻā§°েāĻāϟাāϤ āĻ—āϤিāĻļীāϞāĻ­াā§ąে āĻŽেāĻŽā§°ি āĻ†ā§ąāĻŖ্āϟāύ āϕ⧰িāĻŦāϞৈ।

3. To copy the selected elements from the first array to the second one.

āĻŦাāĻ›āύি āϕ⧰া āωāĻĒাāĻĻাāύāĻŦোā§° āĻĒ্ā§°āĻĨāĻŽ āĻā§°েā§° āĻĒā§°া āĻĻ্āĻŦিāϤীāϝ়āϟোāϞৈ āĻĒ্ā§°āϤিāϞিāĻĒি āϕ⧰িāĻŦāϞৈ।

4. To calculate the summation of these elements.

 āĻāχ āωāĻĒাāĻĻাāύāĻŦোā§°ā§° āϏাā§°াংāĻļ āĻ—āĻŖāύা āϕ⧰িāĻŦāϞৈ।

Sample run:


First array


Second array



Summation: 24


Type & Assamese Translate : Himashree Bora.