Thread: array assignment

  1. #1
    Registered User
    Join Date
    Apr 2017
    Posts
    80

    array assignment

    Why isn't this OK?:

    Code:
    int a[6][2] = {{0x1,0x2}, {0x3,0x4}, {0x5,0x6}, {0x7,0x8}, {0x9,0x10}, {0x11,0x12}};
    int b[1][2];
    b[0] = a[1];
    error: incompatible types in assignment

    Seems that should be OK.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    You can't assign arrays.

    Use memcpy() or a for loop to copy each element one by one.
    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.

  3. #3
    Registered User
    Join Date
    Apr 2017
    Posts
    80
    OK, thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Array assignment
    By Cody Staus in forum C Programming
    Replies: 9
    Last Post: 07-24-2014, 10:57 AM
  2. Help Please ... Array Assignment
    By CoolChica in forum C Programming
    Replies: 8
    Last Post: 04-07-2013, 07:41 PM
  3. Pointer assignment using array name
    By stavos77 in forum C Programming
    Replies: 7
    Last Post: 03-12-2010, 03:12 PM
  4. Need help with an array assignment
    By 3wit in forum C Programming
    Replies: 1
    Last Post: 04-17-2008, 10:52 AM
  5. Operator for array assignment.
    By 39ster in forum C++ Programming
    Replies: 9
    Last Post: 01-06-2008, 11:22 PM

Tags for this Thread