[Solved] local variable ‘content_type’ referenced before assignment

You only set content_type when your form is valid: if comment_form.is_valid(): # … content_type = ContentType.objects.get_for_id(content_type_id) # … else: print(comment_form.errors) So when comment_form.is_valid() is false, the variable is never set. You have the same issue with object_id_data and content_data. Perhaps you need to re-think what should be returned when the form is not correct? It … Read more

[Solved] What do the values in a function do in C?

Technically, the arguments to functions are expressions. Expressions come in many different forms. They can be variables, like in value = fun_1(num1, num2); or they can be constants, like in value = fun_1(1, 12); or even involve operators with other expressions: value = fun_1(fun_1(42, 1) * 3, sizeof “foo”); Note that the expressions must have … Read more

[Solved] What’s wrong with this program in C++?

This should do the work. #include <iostream> using namespace std; void chap(char,int,int); int main() { int x,z,q; char y; cout<<“do you want run program?”; cin>>x; while(x!=0) { cout<<“enter your character: \n”; cin>>y; cout<<“\nenter the number of lines: \n”; cin>>z; cout<<“enter 1 for normal pattern and enter 0 for unnormal pattern : \n”; cin>>q; chap(y,z,q); cout<<“do … Read more

[Solved] What is means of this? [closed]

It could mean that the interviewer wanted to test your reaction to being confronted with invalid source code. I have no idea what the intention of Func()[] = ‘a’; is. The C++ compiler clang 3.4 outputs the following: a.cc:3:9: warning: conversion from string literal to ‘char *’ is deprecated [-Wc++11-compat-deprecated-writable-strings] return “Text”; ^ a.cc:6:1: error: … Read more

[Solved] Number with 0 on the front? [closed]

Numbers prefixed with 0 are treated as octal numbers: $x = 012;//$x is 10 Details here The reason that $x = ‘012’; works is because PHP converts that to an integer without treating it as an octal number. 0 solved Number with 0 on the front? [closed]

[Solved] Explain function returns in c [closed]

Your message functions lack a return type. C deduces it to be int. However, not returning a value from a non-void function is Undefined Behaviour. In your case, the return value from printf has probably been stored in a register, which was not overwritten by message before it itself returned. Thus, the return value propagated. … Read more

[Solved] c++ (My code is stuck in the first function) [closed]

On the following line for(student_type *p; p<=&studs[1]; ++p){ You should initialize the variable p is not initialized. You should set it to a known value. I guess you’d want to initialize it as follows. Also your stop condition goes one too far: use < instead of <=. for(student_type *p=studs; p<&studs[1]; ++p){ 3 solved c++ (My … Read more

[Solved] Segmentation fault when calling a function returning a pointer

Let’s use std::vector: #include <iostream> #include <vector> #include <iomanip> typedef std::vector<double> DoubleArray; DoubleArray v_scalar_prod(double a, double *b, int n) { DoubleArray res(n); for (int i = 0; i < n; i++) { res[i] = a*b[i]; std::cout << std::setprecision(10) << “res = ” << res[i] << ‘\n’; } return res; } int main() { double y[3] … Read more

[Solved] How do i condense this jQuery down so it’s more efficient?

The big thing you can do is avoid running the same query twice, if you know the results haven’t changed. Chain or cache the results of your jQuery calls! Instead of: $(‘#button-active’).hide(); $(‘#button-active’).delay(30).fadeIn(1000); you can use the chainability of jQuery objects. In fact, you’re already doing it in the second line–why not take the extra … Read more

[Solved] What does “const int&” do as a return type?

In general, returning a reference avoids that the return value gets copied, and (if it is not const-qualified) gives you the opportunity to change the “original” value. A return type const T& is often used in conjunction with objects of class type, e.g. std::vector, where copying could result in (unwanted) overhead. In conjunction with elementary … Read more