Thread: output of this

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    75

    output of this

    can anyone help me with this....i was wondering what does "<<" do????? and what does it do over here:-

    Code:
    void g(int b[][SIZE], int m, int n)
    {
                      int j, k, x = 0;
    	for (k = 0; k < n; k++)	             
                                                                                  m = 3, n = 2
    	{	
                              for (j = 0; j < m; j++)	              b = 3 4 << row0
    		x = x + b[j ][k ];	              6 5 << row 1
    		printf(”%d^%4d\n”, k, x);7 2 << row 2
    			}
    		}
    Show output of g(b, m, n)

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    << is bit shifting. It shifts to the left.

    Example:

    printf("1 shifted %d places to the left is %d\n", 3, 1<<3 );

    There is also a right shift, which shifts the opposite direction.

    Think of it as if there was a "binary decimal point" some place, and you shift the whole number to the left or right, while the decimal stays put.

    0000.0000

    left shift:

    00000.000

    right shift:

    0000.0000

    See, there is no real decimal point, but in effect if you visualize it, that's what it looks like it does. Each shift to the left is like increasing by a power of two. Each shift to the right is like dividing in half.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User Dev's Avatar
    Join Date
    Mar 2003
    Posts
    59
    Its a guess of mine and is probably correct.

    those three statement with << when written separate are


    3 4 << row0
    6 5 << row 1
    7 2 << row 2


    So it might be suggesting input array b.

    as

    3 4
    6 5
    7 2

    And the programmer has forgotten to put comments there
    These statements have nothing to do with program as far as my logic says.




    --------------------------------------------------------------------------------

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by Dev
    Its a guess of mine and is probably correct.
    ...
    These statements have nothing to do with program as far as my logic says.
    Yep. That looks like it. I didn't even bother to glance at the code. In C, the only thing << does is a left shift, so that's the answer I gave.

    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Registered User
    Join Date
    Mar 2003
    Posts
    75
    thanks alot dude
    really helped me alot

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. code output...
    By roaan in forum C Programming
    Replies: 6
    Last Post: 07-03-2009, 02:22 AM
  2. Help for my output array
    By qwertysingh in forum C Programming
    Replies: 1
    Last Post: 02-17-2009, 03:08 PM
  3. Replies: 4
    Last Post: 11-30-2005, 04:44 PM
  4. Formatting output into even columns?
    By Uncle Rico in forum C Programming
    Replies: 2
    Last Post: 08-16-2005, 05:10 PM
  5. Output problems with structures
    By Gkitty in forum C Programming
    Replies: 1
    Last Post: 12-16-2002, 05:27 AM