Thread: pointer coding

  1. #1
    Registered User
    Join Date
    Apr 2008

    pointer coding

    #include <stdio.h>
    #include <conio.h>
    void fun(int , int*);
    int main(void){
    int a, i;
    int x = 100,y = 200, z = 300;
    int myArr[] = {18,22,3};
    int *ptr1, *ptr2;
    ptr1 = &y;
    ptr2 = &z;
    printf("%d\n",*ptr1 + x);
    a = *ptr2;
    ptr2 = &x;
    printf("%d %d\n",a, *ptr2);
    fun(a, myArr);
    ptr1 = myArr;
    return 0;
    void fun(int b , int* pr){
    int *p;
    for(p = pr; p < pr+3; p++)
    *p = *p + b;
    For the coding above, what will *p be? what is the value? I have problems tracing this coding..

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Compile and test. You can also use a debugger.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    > I have problems tracing this coding..
    Perhaps some indentation, and the occasional blank line to space things out would help.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Quick Pointer Question
    By gwarf420 in forum C Programming
    Replies: 15
    Last Post: 06-01-2008, 03:47 PM
  2. Parameter passing with pointer to pointer
    By notsure in forum C++ Programming
    Replies: 15
    Last Post: 08-12-2006, 07:12 AM
  3. Direct3D problem
    By cboard_member in forum Game Programming
    Replies: 10
    Last Post: 04-09-2006, 03:36 AM
  4. How did you master pointers?
    By Afrinux in forum C Programming
    Replies: 15
    Last Post: 01-17-2006, 08:23 PM
  5. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM