0% found this document useful (0 votes)
2 views3 pages

Practice Set On Array - Pointers

The document contains a practice set on arrays and pointers for B.Tech III Year students at Maharana Pratap Group of Institutions, Kanpur, for the session 2025-26. It includes various programming questions in C related to pointers, arrays, and string manipulations, along with their reasoning and expected outputs. Additionally, it lists several programming assignments for students to implement algorithms and functions based on given requirements.

Uploaded by

princitrp
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)
2 views3 pages

Practice Set On Array - Pointers

The document contains a practice set on arrays and pointers for B.Tech III Year students at Maharana Pratap Group of Institutions, Kanpur, for the session 2025-26. It includes various programming questions in C related to pointers, arrays, and string manipulations, along with their reasoning and expected outputs. Additionally, it lists several programming assignments for students to implement algorithms and functions based on given requirements.

Uploaded by

princitrp
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

MAHARNA PRATAP GROUP OF INSTITUTIONS ,KANPUR

DSA TRAINING ([Link] III YEAR, EVEN SEM) , SESSION 2025-26


(PRACTICE SET ON ARRAYS & POINTERS)

Output: ray
Ques 1.
int main() Reasoning: arr+2 points to arr[2] , which is
{ "array". *ptr is the string "array".
int arr[5] = {1, 2, 3, 4, 5};
*ptr + 2 moves the pointer to the third
int *p = (int*)(&arr + 1);
printf("%d", *(p - 2)); character ('r').
return 0;
}
Output: 4 Ques 4.

int main()
Reasoning: &arr is a pointer to the entire
{
array ( int(*)[5] ). &arr + 1 moves the pointer past char s[] = "hello";
the whole array. (p-2) moves back by char *p = s;
two int sizes to 4. printf("%c, %c", *(p+1), s[1]);
return 0;
}
Ques 2.

int main()
Ques 5.
{
int a = 10; int main()
int *p = &a; {
int **q = &p; Int a [] ={ 10 ,20 , 30 , 40 ,50 }
int ***r = &q; char *p = a+2;
printf("%d", ***r + **q + *p); printf("%d ", p[-2]);
return 0; return 0;
} }
Output: 30

Ques 3. Ques 6.

#include <stdio.h> int main()


int main() {
{ char str[20] = "abc";
char *arr[] = {"placement", "prep", "array", strcat(str, strcat("d", "ef"));
"pointer"}; printf("%s", str);
char **ptr = arr + 2; return 0;
printf("%s", *ptr + 2); }
return 0;
}

1|Page
Ques 7. Ques 10.

int main() #include <stdio.h>


{ int *fun() {
char s[] = "hello"; int x = 10;
printf("%c", *(&s[1] + 2)); return &x;
return 0; }
} int main() {
int *p = fun();
Ques 8. // printf("%d", *p); // Undefined behavior
printf("Success");
#include <stdio.h> return 0;
int main() { }
int a[3][3] = {1, 2, 3, 4, 5,
6,7, 8, 9};
int (*p)[3] = a; Implement the following programs in any one
printf("%d, ", (*p)[2]); of language (C / C++ / Java).
printf("%d", *(*p+4));
return 0; [Link] to check whether a string is a Anagram or
} not.

12. WAP to check whether a string is Panagram or


Analysis: p is a pointer to an array of 3 not ?
integers. p points to the first
13. WAP to find all Permutations of an input string
row {1,2,3} . (*p)[2] is a[0][2] = 3 . *(*p+4) mov using below techniques :
es 4 integers forward from a[0][0] , pointing
(i) With Recursive Function
to a[1][1] = 5 .
(ii) Using Loops
Output: 3, 5
14. Given a list of integers, find the element that
Ques 9. appears the most frequently.

15. Given an array nums, write a function to move


#include <stdio.h>
all 0s to the end of it while maintaining the relative
int main() {
order of the non-zero elements.
int arr[2][2] = {10, 20, 30, 40};
printf("%d, ", *(*(arr + 1) + 1)); 16. Given an array of integers nums and an integer k,
printf("%d", *(arr[0] + 2)); return the total number of continuous subarrays
return 0; whose sum equals to k.
}
17. Given a string, find the length of the longest
substring without repeating characters.
Analysis: *(*(arr + 1) +
1) is arr[1][1] = 40 . *(arr[0] + 2) is arr[0][2] . 18. Write a program to find the second largest
Since arr[0] has only 2 element in an array. You should solve this problem
without sorting the array. If there are duplicate
elements, arr[0]+2 moves to the next
elements, they should be treated as individual
row, arr[1][0] = 30 . values.

Output: 40, 30 .

2|Page
19. Given a sorted array, remove the duplicates so
each element appears only once. Return the length
of the modified array and modify the input array to
contain unique elements in the first `k` positions,
where `k` is the length of the unique elements.

20. Longest Sub-Array with Sum K:


Given an array of integers arr and an integer K, find
the length of the longest sub-array whose sum is
equal to K. If there is no such sub-array, return 0.

21. Two Sum Problem: Given an array of integers


nums and an integer target, return indices of the
two numbers such that they add up to the target.

22. Implement a user defined function modify_str( )


in which following parameters are passed :
A string , length of string and a character variable
ch. Function works to replace all the occurrences of
character ch in input string and capitalize or
decapitalize it based on character ch.

If Input string is : Assessment


ch is ‘s’

output : ASSeSSment

23. WAP to create a function that accepts a string


of length “len” .String contains some # symbols
.You have to move all the hashes to the front of the
string and return the whole string back and print it.

24. Given a string in which multiple characters are


repeated consecutively. WAP to reduce the size of
this string by counting frequency of repeated
characters and printing this number after each
corresponding character.

Example : If input string is “aaabbbbcc”


Output : a3b4c2

If input is “abcccc”
Output : abc4

**********End***********

3|Page

You might also like