Thread: What's wrong ?

  1. #1
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020

    What's wrong ?

    What's wrong wth the following program that i keep getting compile errors like invalid type argument of unary and subscripted value is neithr array nor pointer ?

    Code:
    #include <stdio.h>
    #define SIZE 5
    
    int main()
    {
       unsigned int values[ SIZE ] = { 2, 4, 6, 8, 10 };
       unsigned int vPtr;
       int i;
    
       printf( "Print values using array subscript notation:\n" );
       for ( i = 0; i < SIZE; i++ )
          printf( "values[ %d ] = %d ", i, values[ i ] );
    
       vPtr = values;
    
       printf( "\nPrint values using pointer/offset notation:\n" );
       for ( i = 0; i < SIZE; i++ )
          printf( "*( vPtr + %d ) = %d", i, *( vPtr + i ) );
    
       printf( "\nPrint values using pointer/offset notation with array name as the pointer:\n" );
       for ( i = 0; i < SIZE; i++ )
          printf( "*( values + %d ) = %d ", i, *( values + i ) );
    
       printf( "\nPrint values using pointer subscripts:\n" );
       for ( i = 0; i < SIZE; i++ )
          printf( "vPtr[ %d ] = %d", i, vPtr[ i ] );
    
       return 0;
    }

  2. #2
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020
    sorry i solved it now, silly mistake, left out the *.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 07-15-2004, 03:30 PM
  2. Debugging-Looking in the wrong places
    By JaWiB in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 11-03-2003, 10:50 PM
  3. Confused: What is wrong with void??
    By Machewy in forum C++ Programming
    Replies: 19
    Last Post: 04-15-2003, 12:40 PM
  4. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 12:01 PM
  5. Whats wrong?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 07-14-2002, 01:04 PM