User Profile
Collapse
-
Thanks a lot , I understood the concept now . -
-
If I am using *(*(arr+i)+j) instead of *((arr+i*n) + j) , then I am unable to get the correct OP , it shows error :
invalid type argument of 'unary *'
I am unable to get this .Leave a comment:
-
If I am using *(*(arr+i)+j) instead of *((arr+i*n) + j) , then I am unable to get the correct OP , it shows error :
invalid type argument of 'unary *'
I am unable to get this .Leave a comment:
-
If I am using *(*(arr+i)+j) instead of *((arr+i*n) + j) , then I am unable to get the correct OP , it shows error :
invalid type argument of 'unary *'
I am unable to get this .Leave a comment:
-
Passing 2D array to a function using single pointer .
Code:#include <stdio.h> void print(int *arr, int m, int n) { int i, j; for (i = 0; i < m; i++) for (j = 0; j < n; j++) printf("%d ", *((arr+i*n) + j)); } int main() { int arr[][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; int m = 3, n = 3; print((int *)arr, m, n); return 0; }
-
Now I got it , just last doubt , can you please explain this statement with an example :
There are no rvalues of array type in C. There are pointer lvalues and rvalues, integer lvalues and rvalues, structure lvalues and rvalues etc... But only lvalue arrays. When you try to convert an lvalue of array type to an rvalue, you no longer have an array, you have a pointer to the array's first member.
I am unable to get what is...Leave a comment:
-
But using typedef , you already defined that you are returning the address of the array of 5 integer , so why to put extra * on the type name IntArray5 in second case , what do we achieve through this extra * here ?Leave a comment:
-
I have one confusion in below code :
IntArray5Ptr func(int arg)
{
int (* temp)[5] = new int[arg][5];
return temp;
}
int main()
{
int (* arrA)[5] = func(4);
}
You can return a pointer to type in addition to returning a type.
So you could define a type to be an element of your array (in the example this is an array of 5 int)
and return...Leave a comment:
-
-
Can you please explain how arr+1 and &arr+1 are converted to rvalues ?Leave a comment:
-
radha gogia started a topic How does pointer arithmetic work in case of printing addresses for a 2D array ?in CHow does pointer arithmetic work in case of printing addresses for a 2D array ?
For 2D arrays , Please explain below concepts :
int main()
{
int matrix[2][5] = {{1,2,3,4,5},{6 ,7,8,9,10}};
printf("%p %p %p ", matrix+1, &matrix+1, &matrix[1][0]);
return 0;
}
I am unable to understand how these expressions work , matrix+1 and &matrix[1][0] return same address , how's that going ? matrix gives the base address , now to it if I add 1 , it should... -
How to find the product of all elements of an array modulo 10^9+7 ?
I have written below code ,for the problem stated on below link under topic Array multiplication , I am unable to get the insight of why is the code not working for any test case ?
https://www.hackerearth .com/practice/math/number-theory/modulus-arithmetic/tutorial/
Code:#include <stdio.h> #include<inttypes.h> #include<stdint.h> #include<math.h> int main()
-
How to find maximum product of two prime numbers in an array ?
I have already posted this question on stackoverflow but still I couldn't get my doubt clarified , my code is not working on 1st and 3rd input ,please clarify this .
http://stackoverflow.com/questions/3...rray/39262723?... -
radha gogia started a topic How to scan multiple lines using scanf when we dont know the end of input ?in CHow to scan multiple lines using scanf when we dont know the end of input ?
I referred this link ,but I am unable to get the logic behind using %[^\n]%*c or %[^\t] as format specifier .
http://stackoverflow.c om/questions/14494309/reading-multiple-lines-of-input-with-scanf
And how to scan multiple lines of input when we don't know the end of input , say in those cases where we have an online compiler which would be giving its own input test cases which can be of any length and we are asked to... -
radha gogia replied to Given an integer ‘K’ and a tree in string format.how to solve below problem ?in CI got the point , I forgot to increment the pointer , input was correct , thankss a lotLeave a comment:
-
radha gogia replied to Given an integer ‘K’ and a tree in string format.how to solve below problem ?in CI am unable to get your point , I entered this string only as input .Leave a comment:
-
radha gogia replied to Given an integer ‘K’ and a tree in string format.how to solve below problem ?in CCode:#include<stdio.h> #include<string.h> int main() {int sum=0; char str[40]; char *ptr; int k; printf("enter string"); gets(str); printf("enter depth"); scanf("%d",&k); ptr=str; int depth =-1; while(*ptr!='\0') { if(*ptr=='(') { depth++; if(depth==k) { sum=sum+*(++ptr)-'0'; }
Leave a comment:
-
radha gogia started a topic Given an integer ‘K’ and a tree in string format.how to solve below problem ?in CGiven an integer ‘K’ and a tree in string format.how to solve below problem ?
Given an integer ‘K’ and a tree in string format. We have to print the sum of all elements at Kth level from root.
0
/ \
5 7
/ \ / \
6 4 1 3
\
9
... -
radha gogia replied to why is the below code not printing the ASCII value of the inputed character ?in CIf that was the case that scanf did not read the character successfully then why is the value of b printed as 1 ?Since scaanf returns the number of inputs read successfully so if character A cannot get inside an int variable then why is the value of b =1 ?Leave a comment:
No activity results to display
Show More
Leave a comment: