Why does flux in closed surface remain constant if exterior charge is altered? Q. Charges $q_1$ and $q_2$ lie inside and outside respectively of a closed surface $S$. Let $E$ be the field at any point on $S$ and $\Phi$ be the flux of $E$ over $S$.
One of the answer is: if $q_2$ changes, $E$ will change but flux will not change.
According to Gauss law,
$$\Phi = \oint_S E \cdot ds \, . \tag{1}$$
Also,
$$\Phi_\text{external} =  q/\epsilon_0 \, . \tag{2}$$
But according to the given answer if the electric field $E$ is changing then the flux should also change since $ds$ is constant.
Also, by formula (1), the flux coming out of the surface should remain constant as $q_1$ inside is constant.
In short, electric field changes, $q_2$ changes, $ds$ is constant. Then, by the given formulas how can the flux change?
The two formulas are contradictory. The answer given in the book is surely correct.
 A: 
But according to the given answer if the electric field $E$ is changing then the flux should also change since $ds$ is constant.

As you say, $E$ does change.
However, it changes both where it enters $S$ and where it exits $S$.
In the integral, the sign of $E \cdot ds$ depends on whether the field is pointing into or out of the surface.
To make this more clear, it is better to remember that $E$ and $ds$ are both vectors.
We should really write $\vec{E}$ and $d\vec{S}$, thus writing the integral as
$$\Phi = \oint_S \vec{E} \cdot d\vec{S} \, .$$
The vector $d\vec{S}$ has magnitude given by the size of the area element and by convention the direction points outward from the surface.
Now it is clear that if the field is pointing into the surface the contribution to the integral is negative, while if the field points out from the surface the contribution is positive.
This is illustrated in the diagram.

So you see that if we e.g. double the value of $q_2$ we double the amount of field entering and exiting $S$, so the total contribution is unchanged (and in particular it's still zero).
We could also move $q_2$ around, while keeping it outside of $S$.
However, even moving $q_2$ around does not change $\Phi$.
The reason for this is quite deep, but can be derived from the simple fact that the electric field of a charge has zero divergence,
$$\vec{\nabla} \cdot \vec{E} = 0 \, .$$
The divergence theorem says that given a vector field $\vec{U}$ and a surface $S$ which encloses a volume $V$,
$$\int_V \vec{\nabla}\cdot \vec{U} dV = \int_S \vec{U} \cdot d\vec{S} \, .$$
Since for the electric field of a charge $\vec{\nabla}\cdot \vec{E}$ is always zero, then the integral is zero no matter whether we move the charge around or change its amplitude.
Now, there is a very important detail I left out.
The divergence of $\vec{E}$ is not truly zero everywhere.
In fact, it is zero everywhere except right at the charge itself.
At the charge, the divergence is actually infinite.
The proper way to write the divergence of the electric field caused by a charge $q$ at position $\mathbf{x}_0$ is
$$\vec{\nabla} \cdot \vec{E} = \delta(\mathbf{x} - \mathbf{x}_0) q / \epsilon_0 \, .$$
If you plug this into the divergence theorem you find that the flux through a surface $S$ caused by this charge is zero if the charge is not inside the surface and $q/\epsilon$ if the charge is inside the surface.
