jagomart
digital resources
picture1_Programming Pdf 185789 | Class04 Cpointers


 178x       Filetype PDF       File size 1.13 MB       Source: cs.nyu.edu


File: Programming Pdf 185789 | Class04 Cpointers
csci ua 0201 computer systems organization c programming pointers structs arrays thomas wies wies cs nyu edu https cs nyu edu wies pointers very powerful but also dangerous concept can ...

icon picture PDF Filetype PDF | Posted on 01 Feb 2023 | 2 years ago
Partial capture of text on file.
            CSCI-UA.0201 
      Computer Systems Organization 
   C Programming – Pointers, Structs, Arrays 
             Thomas Wies 
            wies@cs.nyu.edu 
           https://cs.nyu.edu/wies 
        Pointers: 
     Very powerful but also  
      dangerous concept! 
     Can a function modify its arguments? 
         What if we wanted to implement a function pow_assign() that 
         modified its argument, so that these are equivalent: 
            float p = 2.0;         float p = 2.0; 
            /* p is 2.0 here */    /* p is 2.0 here */ 
            p = pow(p, 5);         pow_assign(p, 5); 
            /* p is 32.0 here */   /* p is 32.0 here */ 
                       Would this work? 
                    void pow_assign(float x, uint exp) 
                    { 
                      float result=1.0; 
                      int i; 
                      for (i=0; (i < exp); i++) { 
                        result = result * x; 
                      } 
                      x = result; 
                    } 
                                                                                                                     NO! 
                                            Remember the stack! 
                               void pow_assign(float x, unsigned int exp) 
                               {                                                                                                                          In C, all arguments are passed 
                                 float result=1.0; 
                                 int i;                                                                                                                   by value 
                                 for (i=0; (i < exp); i++) { 
                                   result = result * x; 
                                 } 
                                 x = result;                                                                                                              But, what if the argument is 
                               } 
                                                                                                                                                          the address of a variable?  
                               main() 
                               { 
                                 float p=2.0; 
                                 pow_assign(p, 5); 
                               } 
                                   float xfloat xfloat x                     2.02.032.0   
                                   uuuiiinnnttt333222___ttt   eeexxxppp      555   
                                   fffllloooaaattt   rrreeesssuuulllttt      1.032.032.0   
                                   float p                                   2.0                                                    Grows 
The words contained in this file might help you see if this file matches what you are looking for:

...Csci ua computer systems organization c programming pointers structs arrays thomas wies cs nyu edu https very powerful but also dangerous concept can a function modify its arguments what if we wanted to implement pow assign that modified argument so these are equivalent float p is here would this work void x uint exp result int i for no remember the stack unsigned in all passed by value address of variable main xfloat uuuiiinnnttt ttt eeexxxppp fffllloooaaattt rrreeesssuuulllttt grows...

no reviews yet
Please Login to review.