What will be output if you will execute following code?
#include<stdio.h>
#include<stdio.h>
char display(char (*)[]);
int main(){
char c;
char character[]={65,66,67,68};
char (*ptr)[]=&character;
c=display(ptr);
printf("%c",c);
return 0;
return 0;
}
char display(char (*s)[]){
**s+=2;
return **s;
}
Output: C
Explanation: Here function display is passing pointer to array of characters and returning char data type.
**s+=2
=>**s=**s+2
=>**ptr=**ptr+2 //s=ptr
=>**&character= **&character+2 //ptr=&character
=>*character=*character+2 //from rule *&p =p
=>character[0]=character[0]+2 //from rule *(p+i)=p[i]
=>character [0] =67
**s=character [0] =67
Note: ASCII value of ‘C’ is 67
Pointer to function
Pointer to array of function
Pointer to array of string
Pointer to structure
pointer to union
Multi level pointer
Pointer to array of pointer to string
Pointer to three dimentional array
Pointer to two dimensional array
Sorting of array using pointer
Pointer to array of array
Pointer to array of union
Pointer to array of structure
Pointer to array of character
Pointer to array of integer
C tutorial
3 comments:
It' been the simplest way to teach Pointers.
Here you will find simple C programming questions with answers basically asked in technical interviews.
Sample C Program For Inserting An Element In An Array.
Sample C Program To Count Frequency Of Elements In An Array.
Sample C Program On Two Dimensional (2-D) Array / Matrix.
Sample C Program To Find Transpose a 3 * 2 matrix.
Sample C Program To Multiply Two 3 * 3 Matrix.
Sample C Program To Add Two 3 * 3 Matrix.
Sample C Program To Swap Two Strings Using strcpy() Function.
Sample C Program To Sort A Given Number Of Strings Using strcmp() Function.
Sample C Program To Display Array Of Strings.
Sample C Program To Convert String To An Integer Using atoi() Function.
Sample C Program To Find The Length Of A String.
Sample C Program To Concatenate Two Strings.
Sample C Program To Swap Two Strings.
Sample C Program To Compare Two Strings.
Sample C Program To Check Whether A String Is Palindrome Or Not.
Sample C Program To Print The Reverse Of A String.
Sample C Program To Join Two Strings.
the way pointers are being taught is really simple & also concept is made very clear.!! Thanks A TON..!! These would be used for briefing !! Thanks A LOT...!!!! :D
Post a Comment