NEWTON

NEWTON


Popular tags

    Cairo: How do I initialize an array in cairo

    Asked

    4 months ago

    8

    views


    0

    I want to do some unit testing and need to pass in a felt* of value [1,2,3] into my function. How do I do this?

    This question was originally posted on Triality

      cairocairo-lang

    1 answers

    0

    Here are 2 approaches:

    1. Use the following code snippet to create an array size 3 using alloc() - make sure you include

    from starkware.cairo.common.alloc import alloc

    let felt_array : felt* = alloc()

    assert [felt_array] = 1

    assert [felt_array+1] = 2

    assert [felt_array+2] = 3

    

    1. Use the new operator to create a fixed sized array in a single line

    tempvar arr : felt* = new (1, 2, 3)

    This answer was originally posted on Triality

    answered

    4 months ago

    Your answer

    NEWTON

    NEWTON