2 votes
Accepted

Pset4 Recover not working

It's a scope issue. You have declared outptr inside of a pair of curly braces - the curly braces that contain the code for the if statement's code block. As soon as the code exits that set of curly ...
Cliff B's user avatar
  • 68.8k
2 votes
Accepted

scope of local variables

Variables are declared in block-scope, available in the current and any of its inner blocks. Variables "shadow" outer ones of the same name. Function parameters work like variables declared for the ...
Blauelf's user avatar
  • 20.9k
2 votes

C: Pset 3: Binary Search - 'expected an exit code of 0, not 1' (not finding n)

Actually what you had written is not a binary search as in each move its not changing the size of array to half of original size. By the way mistake in your code is in line no. 19 and 30 as you are ...
Rahul's user avatar
  • 252
2 votes

Global Variable vs Local variables?

candidate_count is not declared in main. It's a global variable (declared outside of main) on line 20 in the distribution file plurality.c at the time of this writing. The definition of main starts ...
kzidane's user avatar
  • 17.7k
2 votes
Accepted

Substring SQL Search

You need to concatenate the strings '%' + sometext + '%'
curiouskiwi's user avatar
  • 18.7k
1 vote
Accepted

Fundamental issue to understand functions with python ===> Impact on all problems

When you define a function you define it's name and what if any arguments it takes... there is more possible complexity to this available but lets keep things basic for you. first example no ...
UpAndAdam's user avatar
  • 1,311
1 vote

Fundamental issue to understand functions with python ===> Impact on all problems

Your understanding is by and large correct. The key to this particular problem is what you say here you call the function by writing its name, This line if dog in blabla: gives this error message '...
DinoCoderSaurus's user avatar
1 vote
Accepted

pset5 speller Hash table not appearing in the debug50 stack/heap

Look very carefully at all of the areas on the right side of the screen. Did you notice that the area that shows the vars and their content is called local variables? It isn't that the vars you ...
Cliff B's user avatar
  • 68.8k
1 vote

Declaring a variable in loop or outside

You can do what is shown in both of your examples, but you shouldn't. The first is a very bad practice, while the second depends on how it is used. In the first case, it's called creating a shadow ...
Cliff B's user avatar
  • 68.8k
1 vote
Accepted

Pset7 Sell stockprice not a bound parameter

You forgot the : for :stockprice in VALUES (:userID, :symbol, :shares, :amount, stockprice). And to quote Cliff B: If this answers your question, please click on the check mark to accept. Let's ...
Peter Pesch's user avatar
1 vote
Accepted

Printing a character times a variable

Nope, can't do it that way. If you want to print multiple copies of a char based on a var's value, think for loop. If this answers your question, please click on the check mark to accept. Let's ...
Cliff B's user avatar
  • 68.8k
1 vote
Accepted

C: Pset 3: Binary Search - 'expected an exit code of 0, not 1' (not finding n)

When you write int min; int max; you're creating two int variables, but their value is undefined, it's the value that happened to be at that place in memory when they were created. You don't assign ...
Blauelf's user avatar
  • 20.9k
1 vote
Accepted

What does "using" a variable entail and why does this inconsistency come up? (pset1, greedy, general question)

The root of this problem lies in the order of operations. In C, postfix increment (++) binds more tightly than dereference (*). Thus, what the code *coins++; does is not to dereference coins and then ...
Levi Roth's user avatar
  • 188
1 vote
Accepted

Multiplication function error?

Welcome to the point of this exercise! ;-) Floats are very rarely stored as exact values in a computer because they have to be converted from base 10 to base 2. If you were to print out the value ...
Cliff B's user avatar
  • 68.8k
1 vote

global variables and macros

#define a 1 Pre-processor will simply replace every occurrence of a in your source code with 1 before compilation. For instance, if you had a variable called myVar in your source file after ...
anfauglit's user avatar
  • 151
1 vote

calculations vs variables performance

Like almost everything in the programming, the use of recursion must be made in appropriate cases, you are right regarding the excessive memory usage, and the successive return statements are pending ...
MARS's user avatar
  • 5,169
1 vote

Use of functions and variable declarations outside main() on pset1 greedy

The difference between where a variable is declared is scope. Strictly for this discussion, consider main to be a function, even though it is a special one. A local variable is a variable declared ...
Cliff B's user avatar
  • 68.8k
1 vote

Whats's difference between declaring and defining variables?

when you #define DIM_MIN 3, you are defining a constant not a variable. what's the difference? well, there are many differences actually, but probably the most important one is that, in case of a ...
kzidane's user avatar
  • 17.7k
1 vote
Accepted

Whats's difference between declaring and defining variables?

You can use these values throughout your entire code, but you cannot change their values. Therefore it's a useful tool for creating global constants in your code. A bit more info: #define DIM_MIN 3 ...
Daniel Lee's user avatar
1 vote
Accepted

Can I create an element of arbitrary size in a STRUCT?

There are any number of ways to implement what you want. The most obvious would be to declare a struct element that is a 508 byte array. This assumes that you really want to implement a struct. But ...
Cliff B's user avatar
  • 68.8k
1 vote

Difference between Pass by Value and Pass by Reference (a practical example)

For set_int() function, it's not complicated. You understand it correctly. However, things are confusing for C arrays. Actually, to me, accessing array member via bracket notation is just a syntactic ...
aquablitz11's user avatar
1 vote
Accepted

How can I pass an array or a long long unsigned variable as an argument to a function?

You ask: "However, my question remains: what would it take to properly pass a long long as an argument to a function?" Pass the argument to the funcion. Pass it with the correct type. Your function ...
Irene's user avatar
  • 1,687

Only top scored, non community-wiki answers of a minimum length are eligible