Solved

array indexed 11-25

Posted on 2000-03-01
4
218 Views
Last Modified: 2010-07-27
write a program that "creates" an array of int, that consist of 15 elements,indexed by numbers 11 to 25.
the array is to take 15 * sizeof(int)
bytes in memory.(answer has to be in "C" not "C++".
0
Comment
Question by:thesunboy
  • 2
4 Comments
 

Expert Comment

by:mprao
Comment Utility
The following program will solve ur problem


#pragma warning (disable :4786)
#include <iostream>
#include <map>
using namespace std;

void main()
{
  map<int, int> m;  // This is a pair of Key & value . They are associated array.
  for (int i =11,j=100;i<=25 ;i++,j++)
        m[i]=j;
  for (i =11;i<=25 ;i++)
        cout <<"Key : " << i <<"  Value : " <<  m[i] <<endl;
 }
0
 

Author Comment

by:thesunboy
Comment Utility
i need to solve it in
c and not c++
0
 

Author Comment

by:thesunboy
Comment Utility
Edited text of question.
0
 

Accepted Solution

by:
042 earned 50 total points
Comment Utility
int     main()
{
  int*  array;

  if (!(array = malloc(15*sizeof(int)))
    return (1);
  array -= 11;

/* do whatever you want */

  free(array + 11);
  return (0);
}

That's really awfull, i didn't write that, no I didn't!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now