Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Can you use more than one string function at the same time?, Can st...

Is this an array?


int jan, feb;

jan=1; /*first month/*

feb=2; /*second month/*

int array[1]=1, 2 ;

array[0]='jan';

array[1]='feb';


There are only '1' in the brackets of the array(which is called the dimension right? ) well I put in the number 1 cause it only has two variables! of int!

Not forgetting that arrays start at 0 and not 1!


I could go in with that array, but it would go too long, how do I use a two dimensional array to make the months of the year smaller then just typing down years up to 9, december cant be reached because: array[12]='dec'; isnt possible, it only goes to up 1-9


Answer to my subect line also.

this is confusing, how do I know when to put the

return=0

statment at the end of the function main()?

0 means success so do I put it or not? with my main() functions?




Comments

  • : Is this an array?


    : int jan, feb;

    : jan=1; /*first month/*

    : feb=2; /*second month/*

    : int array[1]=1, 2 ;


    The previous line is not legal. You need to wrap your initializer list in curly-braces.


    : array[0]='jan';

    : array[1]='feb';


    Neither of the previous two lines are legal. 'array' is declared above as an array of int. You're attempting to assign to one of the ints of the array a multicharacter constant which is also illegal in C. The only thing you can put into an element of an array of ints is an int. Or something that can be converted to an int.



    : There are only '1' in the brackets of the array(which is called the dimension right? ) well I put in the number 1 cause it only has two variables! of int!


    Your array is declared to have only one element, which means that only array[0] is valid.



    : Not forgetting that arrays start at 0 and not 1!


    Always important to remember. Off-by-one errors are probably the most common logic bugs in C.




    : I could go in with that array, but it would go too long, how do I use a two dimensional array to make the months of the year smaller then just typing down years up to 9, december cant be reached because: array[12]='dec'; isnt possible, it only goes to up 1-9




    array[12]='dec' is only illogical because 'dec' isn't a legal integer and because you've only declared 'array' to have 1 element in it (at index 0). I'd avoid multidimensional arrays until you've figured out singly dimensioned arrays.



    : Answer to my subect line also.


    You can chain functions together in any way that make sense to the compiler. If a function takes, as a parameter, an integer, then you can substitute for that parameter any function that returns an integer. It's up to you to determine how logical this is for a given case.




    : this is confusing, how do I know when to put the

    : return=0

    : statment at the end of the function main()?

    : 0 means success so do I put it or not? with my main() functions?



    You can do a 'return' from any function at any time, and if the function is supposed to return a value then you must specify that you are returning it (in your case 'return 0' for success indication from main).







  • Andre YoungAndre Young USAMember Posts: 0

    ______ | http://forcoder.org | free video tutorials and ebooks about { C, R, C#, C++, Swift, PHP, Visual Basic, Objective-C, Ruby, Java, Perl, Visual Basic .NET, Delphi, MATLAB, Python, Go, Assembly, PL/SQL, Scratch, JavaScript FoxPro, ABAP, SAS, Transact-SQL, Alice, D, COBOL, Dart, ML, Lua, Prolog, Kotlin, Lisp, Ada, Bash, Awk, Apex, Erlang, Scheme, VBScript, Crystal, Hack, Logo, Clojure, Scala, F#, Julia, LabVIEW, Rust, Fortran } ______

Sign In or Register to comment.