Author Topic: array  (Read 1209 times)

thrushitha

  • Full Member
  • ***
  • Posts: 26
array
« on: September 12, 2011, 04:01:30 am »
what is the output for below code

Code:
//Source Code Listing

unsigned int a[5]={ 0,2,4,5,8};
printf("%d %d",a,a[0])
printf("%d",a[0]++);

thanks in advance :)
« Last Edit: November 16, 2011, 04:56:22 pm by kathir »

kathir

  • Administrator
  • Sr. Member
  • *****
  • Posts: 283
Re: array
« Reply #1 on: September 15, 2011, 09:19:11 pm »

what is the output for below code

Code:
//Source Code Listing

unsigned int a[5]={ 0,2,4,5,8};
printf("%d %d",a,a[0])
printf("%d",a[0]++);

thanks in advance :)

First printf will display the pointer address and 0 as content of a[0].

Second printf will display 0, and then internally increment the value by 1 so that a[0] becomes 1.
« Last Edit: November 16, 2011, 04:57:27 pm by kathir »

thrushitha

  • Full Member
  • ***
  • Posts: 26
Re: array
« Reply #2 on: September 30, 2011, 04:38:37 am »
sir, i ahv a suiation wherein i need to convert string into integer, n store that integer values into ant array n access elements of array, say eg: string is "MASK"
Can you  give me peice of code, that performs above operation.


thanx in advance :)



administrator

  • Administrator
  • Full Member
  • *****
  • Posts: 69
Re: array
« Reply #3 on: October 04, 2011, 03:37:46 pm »
sir, i ahv a suiation wherein i need to convert string into integer, n store that integer values into ant array n access elements of array, say eg: string is "MASK"
Can you  give me peice of code, that performs above operation.
thanx in advance :)

It would be direct assignment and internally the ASCII value would be taken. If you want to convert "123" string to a number 123, then use atoi( ) function.

Code:
//Source Code Listing


int main(int argc, char* argv[])
{
   char buf[] = "MASK";
   int arr[32];

   for(int i = 0; i < strlen(buf); i++)
   {     
      std::cout << buf[i] << " : ";
      arr[i] = buf[i];
      std::cout << arr[i] << "\n"; 
   }

  return 0;
}


M : 0100 1101
A : 0100 0001
S : 0101 0011
K : 0100 1011
Press any key to continue . . .



« Last Edit: November 16, 2011, 04:56:53 pm by kathir »

 


Disclaimer: This web site is for educational and informational purposes only. Click here to read the Disclaimer.
Content copyright 2010-2014. Kathiresan. All rights reserved.
This page is using SMF version 2.0.1