Thread: Array assigning error

  1. #1
    Registered User
    Join Date
    Jun 2012
    Posts
    2

    Lightbulb Array assigning error

    Hi,

    while running the below mentioned code i got a error can any one help to fix these error.
    The error message is"cannot convert 'int (*)(s) to int*' in function main() " and "'p' is assigned a value that never used in function main()"

    Code:
    #include<stdio.h>
    #include<conio.h>
    main()
    {
      int s[4][2] = {
        {123, 33},
        {124, 35},
        {125, 36},
        {126, 37}
      };
      int (*p)[2];
      int i, j, *pint;
      for (i = 0; i <= 3; i++) {
        p = &s[i];
        pint = p;
        printf("\n");
        for (j = 0; j < 1; j++)
          printf("%d", *(pint + j));
      }
      getch();
      clrscr();
    }
    Last edited by Salem; 06-28-2012 at 01:04 AM. Reason: demunging useless colour

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    What are you trying to do?
    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
    Location
    The edge of the known universe
    Posts
    39,660
    Try
    pint = p[0];
    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.

  4. #4
    Novice
    Join Date
    Jul 2009
    Posts
    568
    Which one do you want?
    Code:
    int (*p)[2];    // pointer `p` to array of 2 int's
    int *p[2];      // array `p` of 2 pointers to int
    Disclaimer: This post shows my ignorance at the time of its making. I claim ownership of but not responsibility for all errors in it. Reference at your own peril.

  5. #5
    Registered User
    Join Date
    Jun 2012
    Posts
    2
    thanks dude its work

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. bus error when assigning value to member of struct
    By popapez in forum C Programming
    Replies: 4
    Last Post: 09-23-2009, 08:37 PM
  2. error in assigning a path ?
    By GSalah in forum C++ Programming
    Replies: 18
    Last Post: 11-17-2006, 04:48 PM
  3. Assigning the value of a const array to a normal array
    By Accident Prone in forum C++ Programming
    Replies: 6
    Last Post: 08-11-2003, 10:40 PM
  4. Error with assigning ..interrupt value?
    By jawwadalam in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 04-15-2003, 10:28 AM
  5. Assigning std::strings result in error
    By NixPhoeni in forum C++ Programming
    Replies: 4
    Last Post: 12-07-2001, 04:01 PM

Tags for this Thread