SoftwareQuery
Home About Contact

How To Create Jagged Arrays In C

 SoftwareQuery     No comments   




In c programming language jagged array is very important role play in part of the array. The array can be different sizes.it is producing rows of jagged edges.
when visualized as output.a jagged array is an array of array. The difference between a rectangular array and jagged array is rectangular array is one object and
two dimensions or each element is integers but in case of a jagged array, all elements are the different length and different size.

create the jagged array  in C using pointers
int *const jagged[] = {
  (int []) { 0, 1 },
  (int []) { 1, 2, 3 }
};

We are create small example of jagged array-:

we want  to always size of array sizes  :

int jagged[][3] = { {2,4}, {1,2,3} };

int size = sizeof(jagged);

printf("size=%d\n", size);

int* p = (void*)jagged;
for (int i=0;i<(size/(int)sizeof(int));i++)
{
    printf("%d=%d\n", i, *p++);
}
output:
size=24
0=2
1=4
2=0
3=1
4=2
5=3

----------------------------------------------Example of c#---------------------------------------------

We are also creating a jagged array program in c#.let's see the example of the jagged array.

class ArrayTest
{
    static void Main()
    {
        // Declare the array of two elements:
        int[][] arr = new int[2][];

        // Initialize the elements:
        arr[0] = new int[5] { 1, 3, 5, 7, 9 };
        arr[1] = new int[4] { 2, 4, 6, 8 };

        // Display the array elements:
        for (int i = 0; i < arr.Length; i++)
        {
            System.Console.Write("Element({0}): ", i);

            for (int j = 0; j < arr[i].Length; j++)
            {
                System.Console.Write("{0}{1}", arr[i][j], j == (arr[i].Length - 1) ? "" : " ");
            }
            System.Console.WriteLine();          
        }
        // Keep the console window open in debug mode.
        System.Console.WriteLine("Press any key to exit.");
        System.Console.ReadKey();
    }
}
   Output:
    Element(0): 1 3 5 7 9
    Element(1): 2 4 6 8

  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Email ThisBlogThis!Share to TwitterShare to Facebook
Newer Post Older Post Home

0 comments:

Post a comment

Donate

Translate

Popular Posts

  • How to Make Image Upload Code Using AJAX
    Direct Copy Paste PHP File  Image Upload Code -   <html> <head> <meta charset="utf-8"> <meta http-equi...
  • Best Useful Free Plugin to Make Wordpress Theme
    Meta Slider   - Meta Slider is that the initial free possibility on today’s list. A premium version is additionally obtainable...
  • How To Install Magento on Localhost XAMPP OR WAMP SERVER
      Step-1 => Make Sure you have to install Latest Version of  Xampp server or Wamp server in your PC.   Step -2 => Go to Web Bro...
  • How To Intall Node.js Via Command On Window And Linux.
    Step-1 . Firstly We have to go official website of https://nodejs.org/en/ then download the latest version of Nodejs zi...
  • How to Set up Amazon Affiliate Marketing Account to Earn Money
    Amazon Associates is a  marketing of Amazon company. It is allowed to youtube channel owner, Social Media pages owner and any type...
  • How To Create Custom Pagination In WordPress
    Hello, Friend's in this post we are creating a custom code of Pagination in WordPress. It is very easy to put this code any custom...
  • How To Scrape Data From Website Url Using Php.
    Q. why using a Scraping. If we want to get data of another website then using web scraping. It is using a PHP HTML Dom parser library ...
  • How To Install Wordpress in Xampp Server And Wamp Server
      Step 1st  -      Install WampServer or Xampp Server.                                                                               ...
  • How to create facebook share and like button for webpage
    Step-1 . Go to web browser type google and write facebook sharing button click this URL or open this URL.                     Ref URL:...
  • How to create Database Connection with ENCRYPT Password in Php
    <?php  $username = $_POST['username'];   $email = $_POST['email'];  $psw = password_hash($_POST['psw'], PA...

Home

This blog Is very help full for beginner coder,if you want to learn new things definitely this Blog is very
helpful for you guys.

Followers

Contact form

Name

Email *

Message *

Blog

  • Home
  • About Us
  • Privacy Policy
  • Disclaimer
  • Contact Us
  • Terms&Conditions

NewsLetter

Copyright © SoftwareQuery | Powered by softwarequery
Design by ShubhamTiwari | Theme by softwarequery.com | Distributed By softwarequery/