You are not logged in. Please login at www.codechef.com to post your questions!

×

How to allocate array using malloc

I want to allocate arrays that can store 109 variables , how do I do it ? Here's how I'm doing ,think it's not working int arr; arr= (long long )malloc(100000*sizeof(long long)) Anyone , any opinions/suggestions on this ?

asked 07 Apr '15, 14:25

viks1_robot's gravatar image

1★viks1_robot
11
accept rate: 0%


declare int arr as pointer array(*arr) then it will work

link

answered 05 Sep '17, 23:10

pranshu_msak's gravatar image

0★pranshu_msak
11
accept rate: 0%

Allocating memory to array using malloc is the way of dynamically allocating memory . An example of a c programme to allocate memory to an integer array using malloc is given

include<stdio.h>

int main() { int n; printf("Enter the size of array\n"); scanf("%d",&n); int array=(int )malloc(n*sizeof(int)); //malloc syntax return 0; }

link

answered 09 Sep '17, 12:15

amansingh4u98's gravatar image

0★amansingh4u98
1
accept rate: 0%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×862
×26

question asked: 07 Apr '15, 14:25

question was seen: 1,253 times

last updated: 09 Sep '17, 12:15