Results 1 to 9 of 9

Thread: c++ main arrays k lye help chaye..!

  1. #1
    ithoun is offline Senior Member+
    Last Online
    16th September 2014 @ 05:43 PM
    Join Date
    31 May 2010
    Posts
    176
    Threads
    38
    Credits
    760
    Thanked
    24

    Smile c++ main arrays k lye help chaye..!

    As-salam-o-aliukum..
    kyya haal hai dosto bahio buzrgoooo..!
    14 august mubrikh ho..!
    mera sawal ye hai k c++ main arrays ko pehlay say initialize or kuch values kaisay assign karwain gay maslan..agar main int a[5] ki array bnaoun tou main kaisay 1,2,3,4,5; ye panch values pehlay say initialize karwaon ga..khayaal rahay main cin>> nhae karwana chah rha
    wa.salam............
    apkay achay reply ka shidat say intazar rahay ga..!

  2. #2
    Assasin's Avatar
    Assasin is offline Senior Member+
    Last Online
    22nd February 2015 @ 03:33 PM
    Join Date
    25 Aug 2011
    Location
    ☢§†®@ÑG€░Þ@†H§☢
    Age
    31
    Gender
    Male
    Posts
    100
    Threads
    5
    Credits
    577
    Thanked
    5

    Default

    walaikum salam.
    yeh is tarah hoga..
    int a[5] = {1,2,3,5,4};

  3. #3
    ithoun is offline Senior Member+
    Last Online
    16th September 2014 @ 05:43 PM
    Join Date
    31 May 2010
    Posts
    176
    Threads
    38
    Credits
    760
    Thanked
    24

    Default

    waisay mainay tukka mar k kar lyya tha ..anyways thanks alot..!

  4. #4
    AlOnEbOy is offline Senior Member+
    Last Online
    5th October 2013 @ 09:03 PM
    Join Date
    09 Aug 2010
    Location
    Peshawar
    Gender
    Male
    Posts
    109
    Threads
    13
    Credits
    940
    Thanked
    2

    Default

    agar is tarha na karo to phir ye bhi kar sakte ho

    a[0]=1;
    a[1]=2;
    a[2]=3;
    a[3]=4;
    a[4]=5;

  5. #5
    HASEEB610's Avatar
    HASEEB610 is offline Senior Member+
    Last Online
    16th September 2015 @ 12:07 AM
    Join Date
    16 Dec 2011
    Location
    KARACHI
    Gender
    Male
    Posts
    617
    Threads
    42
    Credits
    803
    Thanked
    35

    Default

    agar 5 se ziada hai yani a[500] to for ka loop b laga sakte ho

    for(k=0;k<=499;k++)
    {
    array[k]=k+1;
    }

  6. #6
    swordartonli is offline Junior Member
    Last Online
    10th December 2012 @ 04:42 AM
    Join Date
    08 Dec 2012
    Gender
    Male
    Posts
    17
    Threads
    2
    Credits
    0
    Thanked
    0

    Default

    well im trying it

  7. #7
    padd is offline Junior Member
    Last Online
    7th December 2013 @ 11:49 AM
    Join Date
    07 Apr 2013
    Age
    34
    Gender
    Male
    Posts
    23
    Threads
    2
    Credits
    0
    Thanked: 1

    Default

    asad'afkd

  8. #8
    farimarwat's Avatar
    farimarwat is offline Senior Member+
    Last Online
    28th October 2016 @ 06:03 PM
    Join Date
    09 Nov 2007
    Age
    39
    Posts
    123
    Threads
    20
    Credits
    11
    Thanked: 1

    Default

    If we want to store integer from 1 to 10. If we use simple variables then it will be very difficult that we will declare separate variables.
    Is there any solution? Yes, Array is the solution.

    How to Declare an Array:

    Example:
    int myarray[] = [1, 2, 3, 4, 5 ,6, 7, 8,9,10];

    (int) is the type of data that we will store in myarray[] Array.
    You can put same type of data that you have declared for. In this example we have used int(integer) and we can put only integer in this array.

    (myarray[]) is the name of the array and "[]" square means that the variable which is being declared is array not a single variable.

    (={....]) are the values that we will store in the same variable.

    Now in memory how it look Like:

    "0" = 1
    "1" = 2
    "2" = 3
    "3" = 4
    "4" = 5
    "5" = 6
    "6" = 7
    "7" = 8
    "8" = 9
    "9" = 10

    How it works:
    the compiler creates a place with name "myarray" with 10 cells. the count of the array cells start from 0 not from 1.
    So in cell number 0 compiler will put 1, cell number1 gets 2 and so on.

    Now to print the array or one of its elements we will use index.
    Example:
    to print the 5th element of the array:
    cout << myarray[4] << endl;
    (Every value of the array is called element)
    4 is the index of the array.
    but what is the magic ? we told you that we want to print the 5th element and we put 4 as index? We learn before that array count start from 0 so count it and when you reach to 4 it will be our 5th element.

    You can declare other types of array for example character

    char mychar[] = "Hello World"

    In memor How it look like

    mychar[0] = 'H'
    mychar[1] = 'e'
    mychar[2] = 'l'
    mychar[3] = 'l'
    mychar[4] =' ' (space)
    mychar[5] = 'w'
    mychar[6] = 'o'
    mychar[7] = 'r'
    mychar[8] = 'l'
    mychar[9] = 'd'


    Another Method:

    int mynumbers[3];

    It says to the compiler that go and create a variable(arrray) which length will be 3. Its mean the mynumbers[] will have 3 cells.

    now how to put values after declaration?
    mynumbers[0] = 10;
    mynumbers[1] = 20;
    mynumbers[2] = 30;

    If you have any other problem facing in any language then you are most
    welcome

    BR
    Farimarwat

  9. #9
    gulmac's Avatar
    gulmac is offline Advance Member
    Last Online
    1st January 2024 @ 12:54 PM
    Join Date
    26 Oct 2012
    Location
    Hytbd,Peshawar
    Gender
    Male
    Posts
    1,429
    Threads
    334
    Credits
    -321
    Thanked
    161

Similar Threads

  1. Main Aisi Mohabbat Karta Hoon
    By sibghati in forum Roman Urdu Poetry
    Replies: 285
    Last Post: 21st December 2021, 03:20 AM
  2. Main Aise Mohabbat Karti Hon....1
    By bagi28 in forum Urdu Adab & Shayeri
    Replies: 9
    Last Post: 7th July 2016, 02:50 PM
  3. Solved Eng Main Kar dain achi si achi engain
    By Taha_Ali in forum Solved Problems (IT)
    Replies: 4
    Last Post: 2nd February 2012, 08:11 PM
  4. kasay bataion main tumhain
    By FAKHER HAYAT in forum Urdu Adab & Shayeri
    Replies: 10
    Last Post: 17th November 2009, 02:20 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •