31/07/2013C pointers questions Share 5 More Next Blog» Create Blog Sign In 5 C programming questions and answers C language tricky good pointers questions answers and explanation operators data types arrays structures questions functions recursion preprocessors, looping, file handling, strings questions switch case if else printf advance c linux objective types mcq faq interview questions and answers with explanation and solution for freshers or beginners. Placement online written test prime numbers Armstrong Fibonacci series factorial palindrome code programs examples on c c++ tutorials and pdf C tutorial C Programming Questions C Interview Questions C Programs C Test C programming pdf Program of c++ Create projects Sql Server 5 ► Questions and Answers ► Multiple Choice Questions ► Interviewer Questions Search ► C Programming Language ► C++ Language ► C++ Code C QUESTIONS AND ANSWERS C program examples C interview questions and answers Data type questions Variable naming rule questions Operators questions Control flow questions Switch case questions Looping questions www.cquestions.com/2012/02/c-pointers-questions.html 300 lakh IT jobs* www.Aptech-Education.com Get a global career through Aptech Work in the IT field of your choice Are You a Fresher? www.NIITeducation.com/Graduate Looking for Job. Apply now for NIIT Diploma Programs & get Job-Ready! Top Jobs in Companies. www.monsterindia.com Savillsindia is Hiring. Search & Apply to Jobs. 1/30 31/07/2013 Pointer questions String questions Printf,Scanf questions C pointers questions Jobs. C pointers questions Preprocessor questions Structure questions Commad line argument C questions in Linux C online test C mixed practice sets C pointers interview questions and answers Frequently asked technical objective types multiple choice pointer questions with explanation of placement in c programming language Note: Linux GCC compilers and Visual C++ compiler doesn't support far and huge pointers. C tricky questions Example of recursion in c 1. C programming forums What will be output of following program? C TUTORIAL #include<stdio.h> int main(){ int a = 320; char *ptr; ptr =( char *)&a; printf("%d ",*ptr); return 0; } Memory mapping tutorial in c Variables tutorial in c Data types tutorial in c Storage classes tutorial in c Looping tutorial in c (A) 2 Pointers tutorial in c (B) 320 Function tutorial in c (C) 64 Array tutorial in c (D) Compilation error Preprocessor tutorial in c (E) None of above Advanced c tutorial POPULAR POSTS Output E x p l a n a t i o n : C program examples Check given number is prime number or not using c program C interview questions and answers Turbo C++ 3.0: 64 QUICK SORT USING C PROGRAM www.cquestions.com/2012/02/c-pointers-questions.html 2/30 31/07/2013 C pointers questions Merge sort program in c Program to convert decimal to binary in c Write a c program to reverse a string Find out the perfect number using c program Turbo C ++4.5: 64 Linux GCC: 64 Visual C++: 64 Write a c program to find out sum of digit of given number TO FIND FIBONACCI SERIES USING C PROGRAM SUBSCRIBE VIA EMAIL As we know int is two byte data byte while char is one byte data byte. char pointer can keep the address one byte at time. Binary value of 320 is 00000001 01000000 (In 16 bit) Enter your email address: Memory representation of int a = 320 is: Subscribe Delivered by FeedBurner C PROGRAMMING QUESTIONS AND ANSWER C questions and answers Debugging questions in c with answers Aptitude questions and answers in c C basic questions Multiple choice questions in c So ptr is pointing only first 8 bit which color is green and Decimal value is 64. STANDARD OF QUESTIONS ? Excellent 2. Good What will be output of following program? Avg Worst Vote Show results Votes so far: 5505 Days left to vote: 865 www.cquestions.com/2012/02/c-pointers-questions.html #include<stdio.h> #include<conio.h> int main(){ void (*p)(); int (*q)(); int (*r)(); p = clrscr; 3/30 (*q)().com Looping questions in c and answers C string questions and answers with explanation C operator questions with answers Check the given number is palindrome number or not using c program C pointers questions Turbo C ++4.blogspot. return 0. r and q is pointer to function whose parameter is void and return type is int . (*r)("cquestionbank.com Linux GCC: Compilation error Visual C++: Compilation error Data type questions in c Check given number is prime number or not using c program struct bit fields questions in c C questions answers C interview questions and answers How to test palindrome in c++ p is pointer to function whose parameter is void and return type is also void.cquestions.com Aptitude questions and answers in c (C) c C basic questions (D) Compilation error Multiple choice questions in c Objective questions of c (E) None of above Program in c language Simple program example in c language Tricky c questions and answers Output E x p l a n a t i o n : C programming online test C Linux interview questions and answers Turbo C++ 3.com").blogspot.5: cquestionbank. Palindrome number in c++ Program of palindrome number in c++ C++ code to get sum of all odd numbers in given range 3. What will be output of following program? #include<stdio. C programming questions and answer C questions and answers (A) NULL Debugging questions in c with answers (B) cquestionbank.blogspot. r = puts. (*p)().com/2012/02/c-pointers-questions.html 4/30 .h> int main(){ www.31/07/2013 C pointers questions SUBSCRIBE TO Posts Comments MY HEADLINES } q = getch. So they can hold the address of such function.blogspot.0: cquestionbank. printf("%u %u %d ". Address.com/2012/02/c-pointers-questions. int **k.cquestions.html 5/30 .5: Address. Address Linux GCC: Address. 3 (D) Compilation error (E) None of above Output Explanation: Turbo C++ 3.k. 3 Turbo C ++4. Address. 3. Address. 3 (C) 3.*k. k=&j. 3 Memory representation www. 3 Add to circles (B) Address. 3. Address.**k). Address. return 0. int *j.0: Address.31/07/2013 C pointers questions ABOUT ME ritesh kumar Follow 1.2k View my complete profile GOOGLE+ BADGE } int i = 3. (A) Address. 3 Visual C++: Address. j=&i. 9091 is any arbitrary address.e. Short cut way to calculate: Rule: * and & always cancel to each other i. 8085. *&a = a So *k = *(&j) since k = &j *&j = j = 6024 And **k = **(&j) = *(*&j) = *j = *(&i) = *&i = i = 3 4. it may be different.com/2012/02/c-pointers-questions.html 6/30 . Value of k is content of k in memory which is 8085 Value of *k means content of memory location which address k keeps. k keeps address 8085 .cquestions.31/07/2013 C pointers questions Here 6024. www. Content of at memory location 8085 is 6024 In the same way **k will equal to 3. printf("%d". } (A) 80 (B) 81 (C) 82 (D) Compilation error (E) None of above Output E x p l a n a t i o n : Turbo C++ 3.31/07/2013 C pointers questions What will be output of following program? #include<stdio. return 0.cquestions.*q).com/2012/02/c-pointers-questions. char far *q =(char far *)0x53332225. *p = 80. Physical address of 0x55550005 = (0x5555) * (0x10) + (0x0005) = 0x55555 www.h> int main(){ char far *p =(char far *)0x55550005.5: Compilation error Linux GCC: Compilation error Visual C++: Compilation error Far address of p and q are representing same physical address.html 7/30 .0: 81 Turbo C ++4. (*p)++. } (A) c questions (B) c (null) (C) (null) (null) (D) Compilation error (E) None of above Output E x p l a n a t i o n : Turbo C++ 3. char *ptr2 = 0. strcpy(ptr1.0: (null) (null) Turbo C ++4.cquestions. means content at memory location 0x55555 is assigning value 25 (*p)++ means increase the content by one at memory location 0x5555 so now content at memory location 0x55555 is 81 *q also means content at memory location 0x55555 which is 26 5. printf("\n%s %s".h> #include<string.31/07/2013 C pointers questions Physical address of 0x53332225 = (0x5333 * 0x10) + (0x2225) = 0x55555 *p = 80. strcpy(ptr2.html 8/30 .h> int main(){ char *ptr1 = NULL. return 0.5: Run time error www." c")."questions").ptr1.ptr2).com/2012/02/c-pointers-questions. What will be output of following program? #include<stdio. cquestions.0: power of pointer Turbo C ++4. 6. else printf("power of c"). What will be output of following program? #include<stdio. } (A) power of pointer (B) power of c (C) power of cpower of c (D) Compilation error (E) None of above Output E x p l a n a t i o n : Turbo C++ 3. if(a == b) printf("power of pointer").5: power of c www. return 0.31/07/2013 C pointers questions Linux GCC: Run time error Visual C++: Run time error We cannot assign any string constant in null pointer by strcpy function.html 9/30 .com/2012/02/c-pointers-questions.h> int main(){ int huge *a =(int huge *)0x59990005. int huge *b =(int huge *)0x59980015. return 0. p=&a. } (A) 25 (B) 4 (C) Address (D) Compilation error (E) None of above Output www. int far *p. 7.cquestions. So first of all both a and b will normalize as: a= (0x5999)* (0x10) + (0x0005) =0x9990+0x0005=0x9995 b= (0x5998)* (0x10) + (0x0015) =0x9980+0x0015=0x9995 Here both huge addresses are representing same physical address. What will be output of following program? #include<stdio.31/07/2013 C pointers questions Linux GCC: Compilation error Visual C++: Compilation error Here we are performing relational operation between two huge addresses. So a==b is true.h> int main(){ register a = 25. printf("%d ".html 10/30 .h> #include<string.*p).com/2012/02/c-pointers-questions. printf("%d %d".31/07/2013 C pointers questions E x p l a n a t i o n : Turbo C++ 3.0: 4 4 www.sizeof(p).5: Compilation error Linux GCC: Compilation error Visual C++: Compilation error Register data type stores in CPU. } (A) 2 2 (B) 4 4 (C) 4 2 (D) 2 4 (E) None of above Output E x p l a n a t i o n : Turbo C++ 3.h> int main(){ char far *p.*q. Hence we cannot write &a.sizeof(q)).0: Compilation error Turbo C ++4. What will be output of following program? #include<stdio. return 0. 8. So it has not any memory address.cquestions.html 11/30 .h> #include<string.com/2012/02/c-pointers-questions. 0: 10 www.31/07/2013 C pointers questions Turbo C ++4.h> int main(){ int a = 10.5: 4 4 Linux GCC: Compilation error Visual C++: Compilation error p is far pointer which size is 4 byte.com/2012/02/c-pointers-questions. 9.html 12/30 .*ptr). What will be output of following program? #include<stdio. return 0. By default q is near pointer which size is 2 byte. int *ptr = p.cquestions. printf("%u". void *p = &a. } (A) 10 (B) Address (C) 2 (D) Compilation error (E) None of above Output E x p l a n a t i o n : Turbo C++ 3. cquestions.com/2012/02/c-pointers-questions.a). Any pointer can hold void pointer without type casting. scanf("%d".h> int main(){ int register a.0: Compilation error www. printf("%d".h> #include<string.5: 10 Linux GCC: 10 Visual C++: 10 Void pointer can hold address of any data type without type casting.31/07/2013 C pointers questions Turbo C ++4. 10. return 0. } //if a=25 (A) 25 (B) Address (C) 0 (D) Compilation error (E) None of above Output E x p l a n a t i o n : Turbo C++ 3. What will be output of following program? #include<stdio.&a).html 13/30 . arr). printf("%s". 11. So it has not any memory address. What will be output of following program? #include<stdio. return 0.0: Compilation error Turbo C ++4.html 14/30 . Hence we cannot write &a.h> int main(){ char arr[10]. } (A) world (B) w (C) Null (D) Compilation error (E) None of above Output E x p l a n a t i o n : Turbo C++ 3.5: Compilation error www. arr = "world".31/07/2013 C pointers questions Turbo C ++4.5: Compilation error Linux GCC: Compilation error Visual C++: Compilation error Register data type stores in CPU.cquestions.com/2012/02/c-pointers-questions. char *p = ( char *)0. double *s = 0. b = (int)(q+1). } (A) 2 2 2 2 (B) 1 2 4 8 (C) 1 2 2 4 (D) Compilation error (E) None of above Output www. float *r = ( float *)0.h> #include<string.b.b. a = (int)(p+1). 12.c. int *q = ( int *q)0. d = (int)(s+1). printf("%d %d %d %d".a. What will be output of following program? #include<stdio.cquestions.h> int main(){ int a.html 15/30 .com/2012/02/c-pointers-questions.d. c = (int)(r+1).d).31/07/2013 C pointers questions Linux GCC: Compilation error Visual C++: Compilation error Compilation error Lvalue required Array name is constant pointer and we cannot assign any value in constant data type after declaration.c. return 0. h> int main(){ int a = 5. } (A) 1 (B) 5 (C) -5 www. So its next address will be size of data type. c).com/2012/02/c-pointers-questions.cquestions.html 16/30 .5: Compilation error Linux GCC: Compilation error Visual C++: Compilation error Address + 1 = next address Since initial address of all data type is zero.*q = &b.b = 10.31/07/2013 C pointers questions E x p l a n a t i o n : Turbo C++ 3. c = p .c. What will be output of following program? #include<stdio. int *p = &a. return 0.q. printf("%d" .h> #include<string.0: 1 2 4 8 Turbo C ++4. 13. com/2012/02/c-pointers-questions. } int main(){ unsigned long int (*ptr)[3].html 17/30 . printf("%d" .31/07/2013 C pointers questions (D) Compilation error (E) None of above Output E x p l a n a t i o n : Turbo C++ 3. What will be output of following program? #include<stdio.0: 1 Turbo C ++4. ptr = avg().2.5: 1 Linux GCC: 1 Visual C++: 2 Difference of two same type of pointer is always one.3}. *(*ptr+2)). } (A) 1 (B) 2 (C) 3 (D) Compilation error www. return &arr. return 0.cquestions. 14.h> unsigned long int (* avg())[3]{ static unsigned long int arr[3] = {1. return 0. } (A) 2 (B) 4 (C) 8 (D) Compilation error (E) None of above Output E x p l a n a t i o n : Turbo C++ 3. b.31/07/2013 C pointers questions (E) None of above Output E x p l a n a t i o n : Turbo C++ 3.5: 2 or 4 www.com/2012/02/c-pointers-questions.h> int main(){ int * p .0: 2 or 4 Turbo C ++4.cquestions.html 18/30 .0: 3 Turbo C ++4. b).5: 3 Linux GCC: 3 Visual C++: 3 15. b = sizeof(p). What will be output of following program? #include<stdio. printf("%d" . com/2012/02/c-pointers-questions.5: 5 5 www.cquestions.31/07/2013 C pointers questions Linux GCC: 4 Visual C++: 4 since in this question it has not written p is which type of pointer.html 19/30 . } (A) 5 5 (B) Address Address (C) 5 Address (D) Compilation error (E) None of above Output E x p l a n a t i o n : Turbo C++ 3. What will be output of following program? #include<stdio. 16.*q).0: 5 5 Turbo C ++4. j. printf("%d %d". return 0. Default memory model is small. j = 5. *q.*p. q = &j.h> int main(){ int i = 5 . So its output will depend upon which memory model has selected. p = &i. int *p . 31/07/2013 C pointers questions Linux GCC: 5 5 Visual C++: 5 5 17.html 20/30 . &*p). p = &i.5: Address Address Linux GCC: Address Address Visual C++: Address Address Since * and & always cancel to each other. www. printf(" %u %u". *&p .0: Address Address Turbo C ++4. } (A) 5 Address (B) Address Address (C) Address 5 (D) Compilation error (E) None of above Output E x p l a n a t i o n : Turbo C++ 3.com/2012/02/c-pointers-questions. What will be output of following program? #include<stdio.h> int main(){ int i = 5. int *p.cquestions. return 0. e. } (A) value of i : 100 addresss of i : Address value of i : 101 addresss of i : Address (B) value of i : 100 addresss of i : Address value of i : 100 addresss of i : Address (C) value of i : 101 addresss of i : Address value of i : 101 addresss of i : Address (D) Compilation error (E) None of above www.i. printf("value of i : %d addresss of i : %u". *&a = a so *&p = p which store address of integer i &*p = &*(&i) //since p = &i = &(*&i) = &i So second output is also address of i 18.cquestions.&i).h> int main(){ int i = 100. printf("\nvalue of i : %d addresss of i : %u". return 0. What will be output of following program? #include<stdio.31/07/2013 C pointers questions i.&i). i++.i.com/2012/02/c-pointers-questions.html 21/30 . www.5: value of i : 100 addresss of i : Address value of i : 101 addresss of i : Address Linux GCC: value of i : 100 addresss of i : Address value of i : 101 addresss of i : Address Visual C++: value of i : 100 addresss of i : Address value of i : 101 addresss of i : Address Within the scope of any variable. 19.cquestions.0: value of i : 100 addresss of i : Address value of i : 101 addresss of i : Address Turbo C ++4. value of variable may change but its address will never change in any modification of variable.com/2012/02/c-pointers-questions.html 22/30 .31/07/2013 C pointers questions Output E x p l a n a t i o n : Turbo C++ 3. return 0. (*p)++.5: Compilation error Linux GCC: Compilation error Visual C++: Compilation error Far address of p and q are representing same physical address.html 23/30 . char far *q =(char far *)0x53332225. } (A) 25 (B) Address (C) Garbage (D) Compilation error (E)None of above Output E x p l a n a t i o n : Turbo C++ 3.com/2012/02/c-pointers-questions.*q).h> int main(){ char far *p =(char far *)0x55550005. *p = 25.0: 26 Turbo C ++4. printf("%d".31/07/2013 C pointers questions What will be output of following program? #include<stdio.cquestions. Physical address of 0x55550005 = 0x5555 * ox10 + ox0005 = 0x55555 Physical address of www. k = &j.0: 3 Address Address www.h> int main(){ int i = 3.cquestions.i. } (A) 3 Address 3 (B) 3 Address Address (C) 3 3 3 (D) Compilation error (E) None of above Output E x p l a n a t i o n : Turbo C++ 3. int *j. return 0.com/2012/02/c-pointers-questions.31/07/2013 C pointers questions 0x53332225 = 0x5333 * 0x10 + ox2225 = 0x55555 *p = 25. int **k. means content at memory location 0x55555 is assigning value 25 (*p)++ means to increase the content by one at memory the location 0x5555 so now content of memory location at 0x55555 is 26 *q also means content at memory location 0x55555 which is 26 20.html 24/30 .j.k). j = &i. What will be output of following program? #include<stdio. printf("%u %u %u". Pointer Tutorial More pointer questions Array questions String questions Function questions +5 Recommend this on Google 12 comments: www. 8085.5: 3 Address Address Linux GCC: 3 Address Address Visual C++: 3 Address Address Here 6024. 9091 is any arbitrary address.com/2012/02/c-pointers-questions. it may be different.31/07/2013 C pointers questions Turbo C ++4.html 25/30 .cquestions. b = 10.org which uses linux gcc compiler.q. I mean if they're two consecutive values or they're apart from each other in memory. return &arr.there is no explanation please provide explanation.cquestions. First of all.com/2012/02/c-pointers-questions..3}. ITS VERY GOOD JOB.*q = &d.31/07/2013 C pointers questions bartek 2/15/12.c = 100. int *p = &a. c = p .&b = 3. } www. printf("%d" .otherwise everthing fine. 2:43 AM According to Q13. Try this code #include #include int main(){ int a = 5.. Also. Difference between addresses of a and b is 12 bytes. Difference between two pointers of same type isn't always 1 !!!!!! It depends on they relative location in memory !!!!!! Reply Replies Lokesh Sharma 6/25/13.it is very good for beginners. } Reply Unknown 8/7/12. 7:55 PM Difference of two pointers of same type is 1 and not the size of their data types. 10:55 PM will this program face dangling pointer problem??? #include unsigned long int (* avg())[3]{ static unsigned long int arr[3] = {1. the answer in this question depends on how this 2 variables are allocated on stack.. return 0. the explanation is wrong. c). d = -9..html 26/30 .. 12:12 PM according to Q14.PLEASE KEEP IT UP Reply Laxmipooja Anegundi 8/20/12.2. For example on my Visual C++ in such a declaration: int a = 5. the difference between two pointers of same type is not always 1 as mentioned.b = 10. Try this code on codepad. so if they're 4 bytes ints the difference is &a . com/2012/02/c-pointers-questions. return 0. for examle. 12:03 AM i need a C program that accepts the roll numbers and names of N students from the user … and prints those in the alphabetical order of the name. ptr = avg(). in sorted order of names is given below: anand (14) kumar (11) vinay (12) Reply sahil 9/14/12.cquestions. along with the roll numbers.31/07/2013 C pointers questions int main(){ unsigned long int (*ptr)[3]. 12:50 AM what is O/P of this n please also tell whats the concept behind that o/p? #include main() { www. Enter the number of students: 3 Enter the name of student #1: vinay Enter vinay’s roll number: 12 Enter the name of student #2: anand Enter anand’s roll number: 14 Enter the name of student #3: kumar Enter kumar’s roll number: 11 The list of students.html 27/30 . 12:00 AM i want a C program that takes the input – the mark sheets of N number of students. printf("%d" . } Reply Anonymous 9/14/12. ●Enter the marks for student 1 student name: aaa roll number: 24 marks obtained in 5 subjects: 56 89 87 76 98 ●Enter the roll number of the student to be searched: 22 ●The details of student with roll number 22: name: bbb total marks obtained: 293 Reply Anonymous 9/14/12. *(*ptr+2)). 5:52 PM when i put a=908 why i get -116 as output for program 1 Reply Neeru Nagi 3/22/13.html 28/30 . Reply Neeru Nagi 3/22/13.cquestions. *q=***a. int *p. 5:53 PM ques no 2 is producing error for pointer r Reply Neeru Nagi 3/22/13.31/07/2013 C pointers questions int a[2][2][2] = { {10. 7:57 PM should give an error as q doesn't point to a location. p=&a[2][2][2].com/2012/02/c-pointers-questions.*q).4}.3.*q.8} }.0 Reply www..?? Reply Roja 4/22/13. {5. } Reply Replies Lokesh Sharma 6/25/13. 5:55 PM there is some problem in 9 it is giving error(cant convert void to int) . 12:25 AM 7 Question output 25 in C++ 3.*p.6.7. printf("%d----%d".2. com/2012/02/c-pointers-questions.cquestions..html 29/30 .. Comment as: Google Account Publish Preview Links to this post Create a Link Newer Post Home Older Post Subscribe to: Post Comments (Atom) ► Test Questions ► Questions Answers ► C++ Language ► C Programming PDF SHARE IT Share this on Facebook Tweet this View stats (NEW) Appointment gadget >> MUST VISIT ↑ Grab this Headline Animator C LOVER COMMUNITY www.31/07/2013 C pointers questions Enter your comment. cquestions.com/2012/02/c-pointers-questions.31/07/2013 C pointers questions Join this site w ith Google Friend Connect Members (2584) More » Already a member? Sign in Copyright@ritesh kumar.html 30/30 . www. Powered by Blogger.